Skip to content

Commit 168df8e

Browse files
committed
commands/operator-sdk/*: add Info statements for SDK steps
1 parent 9e5ae1c commit 168df8e

File tree

10 files changed

+56
-18
lines changed

10 files changed

+56
-18
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func apiRun(cmd *cobra.Command, args []string) {
6767

6868
// Create and validate new resource
6969
projutil.MustInProjectRoot()
70+
71+
log.Infof("Generating api version %s for kind %s.", apiVersion, kind)
72+
7073
r, err := scaffold.NewResource(apiVersion, kind)
7174
if err != nil {
7275
log.Fatal(err)
@@ -99,4 +102,6 @@ func apiRun(cmd *cobra.Command, args []string) {
99102

100103
// Run k8s codegen for deepcopy
101104
generate.K8sCodegen()
105+
106+
log.Info("Api generation complete.")
102107
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func controllerRun(cmd *cobra.Command, args []string) {
6060
projutil.MustGoProjectCmd(cmd)
6161

6262
projutil.MustInProjectRoot()
63+
64+
log.Infof("Generating controller version %s for kind %s.", apiVersion, kind)
65+
6366
// Create and validate new resource
6467
r, err := scaffold.NewResource(apiVersion, kind)
6568
if err != nil {
@@ -79,4 +82,6 @@ func controllerRun(cmd *cobra.Command, args []string) {
7982
if err != nil {
8083
log.Fatalf("add scaffold failed: (%v)", err)
8184
}
85+
86+
log.Info("Controller generation complete.")
8287
}

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: 10 additions & 1 deletion
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 build manifests for test-framework.")
197+
193198
absProjectPath := projutil.MustGetwd()
194199
cfg := &input.Config{
195200
Repo: projutil.CheckAndGetProjectGoPkg(),
@@ -204,10 +209,12 @@ func buildFunc(cmd *cobra.Command, args []string) {
204209
&scaffold.TestPod{Image: image, TestNamespaceEnv: test.TestNamespaceEnv},
205210
)
206211
if err != nil {
207-
log.Fatalf("test scaffold failed: (%v)", err)
212+
log.Fatalf("test-framework manifest scaffold failed: (%v)", err)
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
@@ -62,10 +62,10 @@ func K8sCodegen() {
6262
log.Fatalf("failed to parse group versions: (%v)", err)
6363
}
6464

65-
log.Printf("Running code-generation for custom resource group versions: [%s]\n", groupVersions)
65+
log.Infof("Running code-generation for Custom Resource group versions: [%s]\n", groupVersions)
66+
6667
// TODO: Replace generate-groups.sh by building the vendored generators(deepcopy, lister etc)
6768
// and running them directly
68-
// TODO: remove dependency on boilerplate.go.txt
6969
genGroupsCmd := "vendor/k8s.io/code-generator/generate-groups.sh"
7070
args := []string{
7171
"deepcopy",
@@ -80,6 +80,8 @@ func K8sCodegen() {
8080
if err != nil {
8181
log.Fatalf("failed to perform code-generation: (%v)", err)
8282
}
83+
84+
log.Info("Code-generation complete.")
8385
}
8486

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

commands/operator-sdk/cmd/new.go

Lines changed: 13 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"
@@ -80,6 +79,8 @@ func newFunc(cmd *cobra.Command, args []string) {
8079
mustBeNewProject()
8180
verifyFlags()
8281

82+
log.Infof("Creating new %s operator '%s'.", strings.Title(operatorType), projectName)
83+
8384
switch operatorType {
8485
case projutil.OperatorTypeGo:
8586
doScaffold()
@@ -88,6 +89,8 @@ func newFunc(cmd *cobra.Command, args []string) {
8889
doAnsibleScaffold()
8990
}
9091
initGit()
92+
93+
log.Info("Project creation complete.")
9194
}
9295

9396
func parse(args []string) {
@@ -190,6 +193,8 @@ func doAnsibleScaffold() {
190193

191194
// Decide on playbook.
192195
if generatePlaybook {
196+
log.Infof("Generating %s playbook.", strings.Title(operatorType))
197+
193198
err := s.Execute(cfg,
194199
&ansible.Playbook{
195200
Resource: *resource,
@@ -200,11 +205,14 @@ func doAnsibleScaffold() {
200205
}
201206
}
202207

208+
log.Info("Running galaxy-init.")
209+
203210
// Run galaxy init.
204211
cmd := exec.Command(filepath.Join(galaxyInit.AbsProjectPath, galaxyInit.Path))
205212
cmd.Stdout = os.Stdout
206213
cmd.Stderr = os.Stderr
207214
cmd.Run()
215+
208216
// Delete Galxy INIT
209217
// Mac OS tmp directory is /var/folders/_c/..... this means we have to make sure that we get the top level directory to remove
210218
// everything.
@@ -263,18 +271,18 @@ func pullDep() {
263271
if err != nil {
264272
log.Fatalf("looking for dep in $PATH: (%v)", err)
265273
}
266-
fmt.Fprintln(os.Stdout, "Run dep ensure ...")
274+
log.Info("Run dep ensure ...")
267275
execCmd(os.Stdout, dep, ensureCmd, "-v")
268-
fmt.Fprintln(os.Stdout, "Run dep ensure done")
276+
log.Info("Run dep ensure done")
269277
}
270278

271279
func initGit() {
272280
if skipGit {
273281
return
274282
}
275-
fmt.Fprintln(os.Stdout, "Run git init ...")
283+
log.Info("Run git init ...")
276284
execCmd(os.Stdout, "git", "init")
277285
execCmd(os.Stdout, "git", "add", "--all")
278286
execCmd(os.Stdout, "git", "commit", "-q", "-m", "INITIAL COMMIT")
279-
fmt.Fprintln(os.Stdout, "Run git init done")
287+
log.Info("Run git init done")
280288
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func testClusterFunc(cmd *cobra.Command, args []string) error {
6363
if len(args) != 1 {
6464
return fmt.Errorf("operator-sdk test cluster requires exactly 1 argument")
6565
}
66+
67+
log.Info("Testing operator in cluster.")
68+
6669
var pullPolicy v1.PullPolicy
6770
if strings.ToLower(tcConfig.imagePullPolicy) == "always" {
6871
pullPolicy = v1.PullAlways
@@ -141,7 +144,7 @@ func testClusterFunc(cmd *cobra.Command, args []string) error {
141144
time.Sleep(time.Second * 5)
142145
continue
143146
} else if testPod.Status.Phase == v1.PodSucceeded {
144-
fmt.Println("Test Successfully Completed")
147+
log.Info("Cluster test successfully completed.")
145148
return nil
146149
} else if testPod.Status.Phase == v1.PodFailed {
147150
req := kubeclient.CoreV1().Pods(tcConfig.namespace).GetLogs(testPod.Name, &v1.PodLogOptions{})

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
6262
if len(args) != 1 {
6363
log.Fatal("operator-sdk test local requires exactly 1 argument")
6464
}
65+
66+
log.Info("Testing operator locally.")
67+
6568
// if no namespaced manifest path is given, combine deploy/service_account.yaml, deploy/role.yaml, deploy/role_binding.yaml and deploy/operator.yaml
6669
if tlConfig.namespacedManPath == "" {
6770
err := os.MkdirAll(deployTestDir, os.FileMode(fileutil.DefaultDirFileMode))
@@ -134,7 +137,7 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
134137
defer func() {
135138
err := os.Remove(tlConfig.globalManPath)
136139
if err != nil {
137-
log.Fatalf("could not delete global namespace manifest file: (%v)", err)
140+
log.Fatalf("could not delete global manifest file: (%v)", err)
138141
}
139142
}()
140143
}
@@ -160,6 +163,8 @@ func testLocalFunc(cmd *cobra.Command, args []string) {
160163
if err != nil {
161164
log.Fatalf("failed to exec `go %s`: (%v)", strings.Join(testArgs, " "), err)
162165
}
166+
167+
log.Info("Local operator test successfully completed.")
163168
}
164169

165170
// 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
@@ -73,6 +73,9 @@ const (
7373

7474
func upLocalFunc(cmd *cobra.Command, args []string) {
7575
mustKubeConfig()
76+
77+
log.Info("Running the operator locally.")
78+
7679
switch projutil.GetOperatorType() {
7780
case projutil.OperatorTypeGo:
7881
projutil.MustInProjectRoot()
@@ -165,7 +168,7 @@ func upLocalAnsible() {
165168
if err != nil {
166169
log.Fatal(err)
167170
}
168-
log.Info("Ansible operator started succesfully. Exiting.")
171+
log.Info("Exiting.")
169172
}
170173

171174
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)