Skip to content

Commit 1f4929b

Browse files
committed
feat(cli): create run command
This commit creates the foundations of the new CLI, introducing the root command and the `run` command. This latter one will be used to to run the program and will have many sub-commands, which will be added in next commits. Signed-off-by: Elis Lulja <[email protected]>
1 parent 6e30ca7 commit 1f4929b

File tree

5 files changed

+428
-5
lines changed

5 files changed

+428
-5
lines changed

go.mod

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/CloudNativeSDWAN/cnwan-operator
33
go 1.17
44

55
require (
6+
cloud.google.com/go/compute v1.7.0
67
cloud.google.com/go/servicedirectory v1.3.0
78
github.com/aws/aws-sdk-go v1.44.69
89
github.com/aws/aws-sdk-go-v2 v1.16.8
@@ -11,7 +12,7 @@ require (
1112
github.com/beorn7/perks v1.0.1 // indirect
1213
github.com/cespare/xxhash/v2 v2.1.1 // indirect
1314
github.com/coreos/go-semver v0.3.0 // indirect
14-
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
15+
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 // indirect
1516
github.com/davecgh/go-spew v1.1.1 // indirect
1617
github.com/evanphx/json-patch v4.9.0+incompatible // indirect
1718
github.com/fsnotify/fsnotify v1.4.9 // indirect
@@ -41,6 +42,8 @@ require (
4142
github.com/prometheus/client_model v0.2.0 // indirect
4243
github.com/prometheus/common v0.26.0 // indirect
4344
github.com/prometheus/procfs v0.6.0 // indirect
45+
github.com/rs/zerolog v1.27.0
46+
github.com/spf13/cobra v0.0.5
4447
github.com/spf13/pflag v1.0.5 // indirect
4548
github.com/stretchr/testify v1.8.0
4649
go.etcd.io/etcd/api/v3 v3.5.4
@@ -79,8 +82,6 @@ require (
7982
sigs.k8s.io/yaml v1.2.0 // indirect
8083
)
8184

82-
require cloud.google.com/go/compute v1.7.0
83-
8485
require (
8586
github.com/aws/aws-sdk-go-v2/credentials v1.12.10 // indirect
8687
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.9 // indirect
@@ -92,4 +93,7 @@ require (
9293
github.com/aws/aws-sdk-go-v2/service/sts v1.16.10 // indirect
9394
github.com/aws/smithy-go v1.12.0 // indirect
9495
github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect
96+
github.com/inconshreveable/mousetrap v1.0.0 // indirect
97+
github.com/mattn/go-colorable v0.1.12 // indirect
98+
github.com/mattn/go-isatty v0.0.14 // indirect
9599
)

go.sum

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,9 @@ github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmf
145145
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
146146
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
147147
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
148-
github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI=
149148
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
149+
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U=
150+
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
150151
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
151152
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
152153
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
@@ -366,6 +367,7 @@ github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:
366367
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
367368
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
368369
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
370+
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
369371
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
370372
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
371373
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
@@ -404,7 +406,11 @@ github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN
404406
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
405407
github.com/mailru/easyjson v0.7.0/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
406408
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
409+
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
410+
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
407411
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
412+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
413+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
408414
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
409415
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
410416
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -471,6 +477,9 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
471477
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
472478
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
473479
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
480+
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
481+
github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs=
482+
github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U=
474483
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
475484
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
476485
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
@@ -482,6 +491,7 @@ github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B
482491
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
483492
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
484493
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
494+
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
485495
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
486496
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
487497
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -753,6 +763,7 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
753763
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
754764
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
755765
golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
766+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
756767
golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
757768
golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
758769
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

pkg/cluster/kubernetes.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2021 Cisco
1+
// Copyright © 2021, 2022 Cisco
22
//
33
// SPDX-License-Identifier: Apache-2.0
44
//
@@ -133,6 +133,8 @@ func GetEtcdCredentialsSecret(ctx context.Context) (string, string, error) {
133133
return string(secret.Data["username"]), string(secret.Data["password"]), nil
134134
}
135135

136+
// DEPRECATED
137+
// TODO: remove me
136138
func GetOperatorSettingsConfigMap(ctx context.Context) ([]byte, error) {
137139
cli, err := getK8sClientSet()
138140
if err != nil {
@@ -160,3 +162,42 @@ func GetOperatorSettingsConfigMap(ctx context.Context) ([]byte, error) {
160162

161163
return data, err
162164
}
165+
166+
func GetFilesFromConfigMap(ctx context.Context, nsName, name string) ([][]byte, error) {
167+
cli, err := getK8sClientSet()
168+
if err != nil {
169+
return nil, err
170+
}
171+
172+
cfgm, err := cli.CoreV1().ConfigMaps(nsName).Get(ctx, name, metav1.GetOptions{})
173+
if err != nil {
174+
return nil, err
175+
}
176+
177+
data := [][]byte{}
178+
for _, d := range cfgm.Data {
179+
data = append(data, []byte(d))
180+
}
181+
182+
return data, err
183+
}
184+
185+
func GetFilesFromSecret(ctx context.Context, nsName, name string) ([][]byte, error) {
186+
cli, err := getK8sClientSet()
187+
if err != nil {
188+
return nil, err
189+
}
190+
191+
secret, err := cli.CoreV1().Secrets(nsName).Get(ctx, name, metav1.GetOptions{})
192+
if err != nil {
193+
return nil, err
194+
}
195+
196+
data := [][]byte{}
197+
for _, d := range secret.Data {
198+
data = append(data, d)
199+
break
200+
}
201+
202+
return data, nil
203+
}

pkg/command/root.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright © 2022 Cisco
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+
// All rights reserved.
16+
//
17+
// SPDX-License-Identifier: Apache-2.0
18+
19+
package command
20+
21+
import (
22+
"github.com/CloudNativeSDWAN/cnwan-operator/pkg/command/run"
23+
"github.com/spf13/cobra"
24+
)
25+
26+
func GetRootCommand() *cobra.Command {
27+
cmd := &cobra.Command{
28+
Use: "cnwan-operator [COMMAND] [OPTIONS]",
29+
Short: "Watch and synchronize your Kubernetes services on a service registry.",
30+
Example: "cnwan-operator run service-directory --default-region us-east1",
31+
}
32+
33+
// Commands
34+
cmd.AddCommand(run.GetRunCommand())
35+
36+
return cmd
37+
}

0 commit comments

Comments
 (0)