Skip to content

Commit cea6def

Browse files
author
Ish Shah
committed
makefile updates, compiling
1 parent 2295b20 commit cea6def

File tree

5 files changed

+135
-103
lines changed

5 files changed

+135
-103
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ help: ## Show this help screen
4545
all: format test build/operator-sdk ## Test and Build the Operator SDK
4646

4747
# Code management.
48-
.PHONY: test format tidy clean
48+
.PHONY: format tidy clean doc
4949

5050
format: ## Format the source code
5151
$(Q)go fmt $(PKGS)
@@ -56,6 +56,9 @@ tidy: ## Update dependencies
5656
clean: ## Clean up the build artifacts
5757
$(Q)rm -rf build
5858

59+
doc: ## Generate CLI Documentation
60+
go run ./hack/doc/gen-cli-doc.go
61+
5962
# Build/install/release the SDK.
6063
.PHONY: install release_builds release
6164

cmd/operator-sdk/cli/cli.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2019 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
19+
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
20+
// to ensure that `run` and `up local` can make use of them.
21+
_ "k8s.io/client-go/plugin/pkg/client/auth"
22+
23+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
24+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
25+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
26+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
27+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
28+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate"
29+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/new"
30+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/olmcatalog"
31+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/printdeps"
32+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/run"
33+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard"
34+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/test"
35+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/up"
36+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/version"
37+
"github.com/operator-framework/operator-sdk/internal/flags"
38+
"github.com/operator-framework/operator-sdk/internal/util/projutil"
39+
40+
log "github.com/sirupsen/logrus"
41+
"github.com/spf13/cobra"
42+
"github.com/spf13/viper"
43+
)
44+
45+
// GetCLIRoot is intended to creeate the base command structure for the OSDK for use in CLI and documentation
46+
func GetCLIRoot() *cobra.Command {
47+
root := &cobra.Command{
48+
Use: "operator-sdk",
49+
Short: "An SDK for building operators with ease",
50+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
51+
if viper.GetBool(flags.VerboseOpt) {
52+
if err := projutil.SetGoVerbose(); err != nil {
53+
log.Fatalf("Could not set GOFLAGS: (%v)", err)
54+
}
55+
log.SetLevel(log.DebugLevel)
56+
log.Debug("Debug logging is set")
57+
}
58+
if err := checkGoModulesForCmd(cmd); err != nil {
59+
log.Fatal(err)
60+
}
61+
},
62+
}
63+
64+
root.AddCommand(add.NewCmd())
65+
root.AddCommand(alpha.NewCmd())
66+
root.AddCommand(build.NewCmd())
67+
root.AddCommand(completion.NewCmd())
68+
root.AddCommand(generate.NewCmd())
69+
root.AddCommand(migrate.NewCmd())
70+
root.AddCommand(new.NewCmd())
71+
root.AddCommand(olmcatalog.NewCmd())
72+
root.AddCommand(printdeps.NewCmd())
73+
root.AddCommand(run.NewCmd())
74+
root.AddCommand(scorecard.NewCmd())
75+
root.AddCommand(test.NewCmd())
76+
root.AddCommand(up.NewCmd())
77+
root.AddCommand(version.NewCmd())
78+
79+
return root
80+
}
81+
82+
func checkGoModulesForCmd(cmd *cobra.Command) (err error) {
83+
// Certain commands are able to be run anywhere or handle this check
84+
// differently in their CLI code.
85+
if skipCheckForCmd(cmd) {
86+
return nil
87+
}
88+
// Do not perform this check if the project is non-Go, as they will not
89+
// be using go modules.
90+
if !projutil.IsOperatorGo() {
91+
return nil
92+
}
93+
// Do not perform a go modules check if the working directory is not in
94+
// the project root, as some sub-commands might not require project root.
95+
// Individual subcommands will perform this check as needed.
96+
if err := projutil.CheckProjectRoot(); err != nil {
97+
return nil
98+
}
99+
100+
return projutil.CheckGoModules()
101+
}
102+
103+
var commandsToSkip = map[string]struct{}{
104+
"new": struct{}{}, // Handles this logic in cmd/operator-sdk/new
105+
"migrate": struct{}{}, // Handles this logic in cmd/operator-sdk/migrate
106+
"operator-sdk": struct{}{}, // Alias for "help"
107+
"help": struct{}{},
108+
"completion": struct{}{},
109+
"version": struct{}{},
110+
"print-deps": struct{}{}, // Does not require this logic
111+
}
112+
113+
func skipCheckForCmd(cmd *cobra.Command) (skip bool) {
114+
if _, ok := commandsToSkip[cmd.Name()]; ok {
115+
return true
116+
}
117+
cmd.VisitParents(func(pc *cobra.Command) {
118+
if _, ok := commandsToSkip[pc.Name()]; ok {
119+
// The bare "operator-sdk" command will be checked above.
120+
if pc.Name() != "operator-sdk" {
121+
skip = true
122+
}
123+
}
124+
})
125+
return skip
126+
}

cmd/operator-sdk/main.go

Lines changed: 2 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,15 @@ import (
2121
// to ensure that `run` and `up local` can make use of them.
2222
_ "k8s.io/client-go/plugin/pkg/client/auth"
2323

24-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/add"
25-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/alpha"
26-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/build"
27-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/completion"
28-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/generate"
29-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/migrate"
30-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/new"
31-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/olmcatalog"
32-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/printdeps"
33-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/run"
34-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/scorecard"
35-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/test"
36-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/up"
37-
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/version"
24+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli"
3825
"github.com/operator-framework/operator-sdk/internal/flags"
39-
"github.com/operator-framework/operator-sdk/internal/util/projutil"
4026

4127
log "github.com/sirupsen/logrus"
42-
"github.com/spf13/cobra"
4328
"github.com/spf13/viper"
4429
)
4530

4631
func main() {
47-
root := GetCLIRoot()
32+
root := cli.GetCLIRoot()
4833

4934
root.PersistentFlags().Bool(flags.VerboseOpt, false, "Enable verbose logging")
5035
if err := viper.BindPFlags(root.PersistentFlags()); err != nil {
@@ -55,86 +40,3 @@ func main() {
5540
os.Exit(1)
5641
}
5742
}
58-
59-
// GetCLIRoot is intended to creeate the base command structure for the OSDK for use in CLI and documentation
60-
func GetCLIRoot() *cobra.Command {
61-
root := &cobra.Command{
62-
Use: "operator-sdk",
63-
Short: "An SDK for building operators with ease",
64-
PersistentPreRun: func(cmd *cobra.Command, args []string) {
65-
if viper.GetBool(flags.VerboseOpt) {
66-
if err := projutil.SetGoVerbose(); err != nil {
67-
log.Fatalf("Could not set GOFLAGS: (%v)", err)
68-
}
69-
log.SetLevel(log.DebugLevel)
70-
log.Debug("Debug logging is set")
71-
}
72-
if err := checkGoModulesForCmd(cmd); err != nil {
73-
log.Fatal(err)
74-
}
75-
},
76-
}
77-
78-
root.AddCommand(add.NewCmd())
79-
root.AddCommand(alpha.NewCmd())
80-
root.AddCommand(build.NewCmd())
81-
root.AddCommand(completion.NewCmd())
82-
root.AddCommand(generate.NewCmd())
83-
root.AddCommand(migrate.NewCmd())
84-
root.AddCommand(new.NewCmd())
85-
root.AddCommand(olmcatalog.NewCmd())
86-
root.AddCommand(printdeps.NewCmd())
87-
root.AddCommand(run.NewCmd())
88-
root.AddCommand(scorecard.NewCmd())
89-
root.AddCommand(test.NewCmd())
90-
root.AddCommand(up.NewCmd())
91-
root.AddCommand(version.NewCmd())
92-
93-
return root
94-
}
95-
96-
func checkGoModulesForCmd(cmd *cobra.Command) (err error) {
97-
// Certain commands are able to be run anywhere or handle this check
98-
// differently in their CLI code.
99-
if skipCheckForCmd(cmd) {
100-
return nil
101-
}
102-
// Do not perform this check if the project is non-Go, as they will not
103-
// be using go modules.
104-
if !projutil.IsOperatorGo() {
105-
return nil
106-
}
107-
// Do not perform a go modules check if the working directory is not in
108-
// the project root, as some sub-commands might not require project root.
109-
// Individual subcommands will perform this check as needed.
110-
if err := projutil.CheckProjectRoot(); err != nil {
111-
return nil
112-
}
113-
114-
return projutil.CheckGoModules()
115-
}
116-
117-
var commandsToSkip = map[string]struct{}{
118-
"new": struct{}{}, // Handles this logic in cmd/operator-sdk/new
119-
"migrate": struct{}{}, // Handles this logic in cmd/operator-sdk/migrate
120-
"operator-sdk": struct{}{}, // Alias for "help"
121-
"help": struct{}{},
122-
"completion": struct{}{},
123-
"version": struct{}{},
124-
"print-deps": struct{}{}, // Does not require this logic
125-
}
126-
127-
func skipCheckForCmd(cmd *cobra.Command) (skip bool) {
128-
if _, ok := commandsToSkip[cmd.Name()]; ok {
129-
return true
130-
}
131-
cmd.VisitParents(func(pc *cobra.Command) {
132-
if _, ok := commandsToSkip[pc.Name()]; ok {
133-
// The bare "operator-sdk" command will be checked above.
134-
if pc.Name() != "operator-sdk" {
135-
skip = true
136-
}
137-
}
138-
})
139-
return skip
140-
}

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbp
7171
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
7272
github.com/coreos/prometheus-operator v0.29.0 h1:Moi4klbr1xUVaofWzlaM12mxwCL294GiLW2Qj8ku0sY=
7373
github.com/coreos/prometheus-operator v0.29.0/go.mod h1:SO+r5yZUacDFPKHfPoUjI3hMsH+ZUdiuNNhuSq3WoSg=
74+
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
7475
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
7576
github.com/cyphar/filepath-securejoin v0.2.2 h1:jCwT2GTP+PY5nBz3c/YL5PAIbusElVrPujOBSCj8xRg=
7677
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=

hack/doc/gen-cli-doc.go

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

1717
import (
18-
cmd "github.com/operator-framework/operator-sdk/cmd/operator-sdk"
18+
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/cli"
1919

2020
"github.com/spf13/cobra/doc"
2121

2222
log "github.com/sirupsen/logrus"
2323
)
2424

2525
func main() {
26-
root := cmd.GetCLIRoot()
26+
root := cli.GetCLIRoot()
2727

2828
err := doc.GenMarkdownTree(root, "../../doc")
2929
if err != nil {

0 commit comments

Comments
 (0)