Skip to content

Commit a3a1a47

Browse files
committed
commands/operator-sdk/*: add Info statements for SDK steps
1 parent b62e7d1 commit a3a1a47

File tree

10 files changed

+58
-16
lines changed

10 files changed

+58
-16
lines changed

commands/operator-sdk/cmd/add/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Example:
6464
func apiRun(cmd *cobra.Command, args []string) {
6565
// Create and validate new resource
6666
projutil.MustInProjectRoot()
67+
68+
log.Infof("Generating api version %s for kind %s.", apiVersion, kind)
69+
6770
r, err := scaffold.NewResource(apiVersion, kind)
6871
if err != nil {
6972
log.Fatal(err)
@@ -96,4 +99,6 @@ func apiRun(cmd *cobra.Command, args []string) {
9699

97100
// Run k8s codegen for deepcopy
98101
generate.K8sCodegen()
102+
103+
log.Info("Api generation complete.")
99104
}

commands/operator-sdk/cmd/add/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ Example:
5757

5858
func controllerRun(cmd *cobra.Command, args []string) {
5959
projutil.MustInProjectRoot()
60+
61+
log.Infof("Generating controller version %s for kind %s.", apiVersion, kind)
62+
6063
// Create and validate new resource
6164
r, err := scaffold.NewResource(apiVersion, kind)
6265
if err != nil {
@@ -76,4 +79,6 @@ func controllerRun(cmd *cobra.Command, args []string) {
7679
if err != nil {
7780
log.Fatalf("add scaffold failed: (%v)", err)
7881
}
82+
83+
log.Info("Controller generation complete.")
7984
}

commands/operator-sdk/cmd/add/crd.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package add
1616

1717
import (
18-
"fmt"
1918
"os"
2019
"path/filepath"
2120
"strings"
@@ -60,7 +59,7 @@ func crdFunc(cmd *cobra.Command, args []string) {
6059
verifyCrdFlags()
6160
verifyCrdDeployPath()
6261

63-
fmt.Println("Generating custom resource definition (CRD) file")
62+
log.Infof("Generating Custom Resource Definition (CRD) version %s for kind %s.", apiVersion, kind)
6463

6564
// generate CR/CRD file
6665
resource, err := scaffold.NewResource(apiVersion, kind)
@@ -81,6 +80,8 @@ func crdFunc(cmd *cobra.Command, args []string) {
8180
if err := scaffold.UpdateRoleForResource(resource, cfg.AbsProjectPath); err != nil {
8281
log.Fatalf("failed to update the RBAC manifest for the resource (%v, %v): (%v)", resource.APIVersion, resource.Kind, err)
8382
}
83+
84+
log.Info("CRD generation complete.")
8485
}
8586

8687
func verifyCrdFlags() {

commands/operator-sdk/cmd/build.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ func buildFunc(cmd *cobra.Command, args []string) {
163163
if enableTests {
164164
baseImageName += "-intermediate"
165165
}
166+
167+
log.Infof("Building Docker image %s", baseImageName)
168+
166169
dbcmd := exec.Command("docker", "build", ".", "-f", "build/Dockerfile", "-t", baseImageName)
167170
dbcmd.Stdout = os.Stdout
168171
dbcmd.Stderr = os.Stderr
@@ -190,6 +193,8 @@ func buildFunc(cmd *cobra.Command, args []string) {
190193
_, err = os.Stat(testDockerfile)
191194
if err != nil && os.IsNotExist(err) {
192195

196+
log.Info("Generating operator test files.")
197+
193198
absProjectPath := projutil.MustGetwd()
194199
cfg := &input.Config{
195200
Repo: projutil.CheckAndGetCurrPkg(),
@@ -208,6 +213,8 @@ func buildFunc(cmd *cobra.Command, args []string) {
208213
}
209214
}
210215

216+
log.Infof("Building test Docker image %s", image)
217+
211218
testDbcmd := exec.Command("docker", "build", ".", "-f", testDockerfile, "-t", image, "--build-arg", "NAMESPACEDMAN="+namespacedManBuild, "--build-arg", "BASEIMAGE="+baseImageName)
212219
testDbcmd.Stdout = os.Stdout
213220
testDbcmd.Stderr = os.Stderr
@@ -218,6 +225,8 @@ func buildFunc(cmd *cobra.Command, args []string) {
218225
// Check image name of deployments in namespaced manifest
219226
verifyTestManifest(image)
220227
}
228+
229+
log.Info("Operator build complete.")
221230
}
222231

223232
func mainExists() bool {

commands/operator-sdk/cmd/generate/k8s.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ func K8sCodegen() {
5757
log.Fatalf("failed to parse group versions: (%v)", err)
5858
}
5959

60-
log.Printf("Running code-generation for custom resource group versions: [%s]\n", groupVersions)
60+
log.Infof("Running code-generation for Custom Resource group versions: [%s]\n", groupVersions)
61+
6162
// TODO: Replace generate-groups.sh by building the vendored generators(deepcopy, lister etc)
6263
// and running them directly
63-
// TODO: remove dependency on boilerplate.go.txt
6464
genGroupsCmd := "vendor/k8s.io/code-generator/generate-groups.sh"
6565
args := []string{
6666
"deepcopy",
@@ -75,6 +75,8 @@ func K8sCodegen() {
7575
if err != nil {
7676
log.Fatalf("failed to perform code-generation: (%v)", err)
7777
}
78+
79+
log.Info("Code-generation complete.")
7880
}
7981

8082
// getGroupVersions parses the layout of pkg/apis to return the API groups and versions

commands/operator-sdk/cmd/new.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package cmd
1616

1717
import (
18-
"fmt"
1918
"io/ioutil"
2019
"os"
2120
"os/exec"
@@ -82,6 +81,8 @@ func newFunc(cmd *cobra.Command, args []string) {
8281
mustBeNewProject()
8382
verifyFlags()
8483

84+
log.Infof("Creating new %s operator '%s'.", strings.Title(operatorType), projectName)
85+
8586
switch operatorType {
8687
case projutil.OperatorTypeGo:
8788
doScaffold()
@@ -90,6 +91,8 @@ func newFunc(cmd *cobra.Command, args []string) {
9091
doAnsibleScaffold()
9192
}
9293
initGit()
94+
95+
log.Info("Project creation complete.")
9396
}
9497

9598
func parse(args []string) {
@@ -119,6 +122,8 @@ func mustBeNewProject() {
119122
}
120123

121124
func doScaffold() {
125+
log.Infof("Generating %s project scaffold.", strings.Title(operatorType))
126+
122127
cfg := &input.Config{
123128
Repo: filepath.Join(projutil.CheckAndGetCurrPkg(), projectName),
124129
AbsProjectPath: filepath.Join(projutil.MustGetwd(), projectName),
@@ -145,6 +150,8 @@ func doScaffold() {
145150
}
146151

147152
func doAnsibleScaffold() {
153+
log.Infof("Generating %s project scaffold.", strings.Title(operatorType))
154+
148155
cfg := &input.Config{
149156
AbsProjectPath: filepath.Join(projutil.MustGetwd(), projectName),
150157
ProjectName: projectName,
@@ -192,6 +199,8 @@ func doAnsibleScaffold() {
192199

193200
// Decide on playbook.
194201
if generatePlaybook {
202+
log.Infof("Generating %s playbook.", strings.Title(operatorType))
203+
195204
err := s.Execute(cfg,
196205
&ansible.Playbook{
197206
Resource: *resource,
@@ -202,11 +211,14 @@ func doAnsibleScaffold() {
202211
}
203212
}
204213

214+
log.Info("Running galaxy-init.")
215+
205216
// Run galaxy init.
206217
cmd := exec.Command(filepath.Join(galaxyInit.AbsProjectPath, galaxyInit.Path))
207218
cmd.Stdout = os.Stdout
208219
cmd.Stderr = os.Stderr
209220
cmd.Run()
221+
210222
// Delete Galxy INIT
211223
// Mac OS tmp directory is /var/folders/_c/..... this means we have to make sure that we get the top level directory to remove
212224
// everything.
@@ -287,18 +299,18 @@ func pullDep() {
287299
if err != nil {
288300
log.Fatalf("looking for dep in $PATH: (%v)", err)
289301
}
290-
fmt.Fprintln(os.Stdout, "Run dep ensure ...")
302+
log.Info("Run dep ensure ...")
291303
execCmd(os.Stdout, dep, ensureCmd, "-v")
292-
fmt.Fprintln(os.Stdout, "Run dep ensure done")
304+
log.Info("Run dep ensure done")
293305
}
294306

295307
func initGit() {
296308
if skipGit {
297309
return
298310
}
299-
fmt.Fprintln(os.Stdout, "Run git init ...")
311+
log.Info("Run git init ...")
300312
execCmd(os.Stdout, "git", "init")
301313
execCmd(os.Stdout, "git", "add", "--all")
302314
execCmd(os.Stdout, "git", "commit", "-q", "-m", "INITIAL COMMIT")
303-
fmt.Fprintln(os.Stdout, "Run git init done")
315+
log.Info("Run git init done")
304316
}

commands/operator-sdk/cmd/test/cluster.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func testClusterFunc(cmd *cobra.Command, args []string) error {
6969
if len(args) != 1 {
7070
return fmt.Errorf("operator-sdk test cluster requires exactly 1 argument")
7171
}
72+
73+
log.Info("Testing operator in cluster.")
74+
7275
var pullPolicy v1.PullPolicy
7376
if strings.ToLower(tcConfig.imagePullPolicy) == "always" {
7477
pullPolicy = v1.PullAlways
@@ -144,7 +147,7 @@ func testClusterFunc(cmd *cobra.Command, args []string) error {
144147
time.Sleep(time.Second * 5)
145148
continue
146149
} else if testPod.Status.Phase == v1.PodSucceeded {
147-
fmt.Println("Test Successfully Completed")
150+
log.Info("Cluster test successfully completed.")
148151
return nil
149152
} else if testPod.Status.Phase == v1.PodFailed {
150153
req := kubeclient.CoreV1().Pods(tcConfig.namespace).GetLogs(testPod.Name, &v1.PodLogOptions{})

commands/operator-sdk/cmd/test/local.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
6767
if len(args) != 1 {
6868
log.Fatal("operator-sdk test local requires exactly 1 argument")
6969
}
70+
71+
log.Info("Testing operator locally.")
72+
7073
// if no namespaced manifest path is given, combine deploy/service_account.yaml, deploy/role.yaml, deploy/role_binding.yaml and deploy/operator.yaml
7174
if tlConfig.namespacedManPath == "" {
7275
err := os.MkdirAll(deployTestDir, os.FileMode(fileutil.DefaultDirFileMode))
@@ -165,6 +168,8 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
165168
if err != nil {
166169
log.Fatalf("failed to exec `go %s`: (%v)", strings.Join(testArgs, " "), err)
167170
}
171+
172+
log.Info("Local operator test successfully completed.")
168173
}
169174

170175
// combineManifests combines a given manifest with a base manifest and adds yaml

commands/operator-sdk/cmd/up/local.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ const (
7070

7171
func upLocalFunc(cmd *cobra.Command, args []string) {
7272
mustKubeConfig()
73+
74+
log.Info("Bringing operator up locally.")
75+
7376
switch projutil.GetOperatorType() {
7477
case projutil.OperatorTypeGo:
7578
projutil.MustInProjectRoot()
@@ -155,7 +158,7 @@ func upLocalAnsible() {
155158
if err != nil {
156159
log.Fatal(err)
157160
}
158-
log.Info("Ansible operator started succesfully. Exiting.")
161+
log.Info("Exiting.")
159162
}
160163

161164
func printVersion() {

commands/operator-sdk/main.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
package main
1616

1717
import (
18-
"fmt"
19-
"os"
20-
2118
"github.com/operator-framework/operator-sdk/commands/operator-sdk/cmd"
19+
log "github.com/sirupsen/logrus"
2220
)
2321

2422
func main() {
2523
if err := cmd.NewRootCmd().Execute(); err != nil {
26-
fmt.Fprintln(os.Stderr, err)
27-
os.Exit(-1)
24+
log.Fatal(err)
2825
}
2926
}

0 commit comments

Comments
 (0)