@@ -16,7 +16,10 @@ package operator
1616
1717import (
1818 "context"
19+ "errors"
1920 "fmt"
21+ "net"
22+ "strings"
2023
2124 "github.com/google/go-github/v61/github"
2225 "github.com/mongodb/atlas-cli-core/config"
@@ -53,6 +56,7 @@ type InstallOpts struct {
5356 featureDeletionProtection bool
5457 featureSubDeletionProtection bool
5558 configOnly bool
59+ ipAccessList string
5660}
5761
5862func (opts * InstallOpts ) defaults () error {
@@ -103,6 +107,23 @@ func (opts *InstallOpts) ValidateWatchNamespace() error {
103107 return nil
104108}
105109
110+ func (opts * InstallOpts ) ValidateIpAccessList () error {
111+ if opts .ipAccessList == "" {
112+ return errors .New ("IP access list cannot be empty" )
113+ }
114+
115+ list := strings .Split (opts .ipAccessList , "," )
116+ for _ , entry := range list {
117+ if _ , _ , err := net .ParseCIDR (entry ); err != nil {
118+ if net .ParseIP (entry ) == nil {
119+ return fmt .Errorf ("IP access list \" %s\" must be a valid IP address or CIDR" , entry )
120+ }
121+ }
122+ }
123+
124+ return nil
125+ }
126+
106127func (opts * InstallOpts ) Run (ctx context.Context ) error {
107128 kubeCtl , err := kubernetes .NewKubeCtl (opts .KubeConfig , opts .KubeContext )
108129 if err != nil {
@@ -129,7 +150,7 @@ func (opts *InstallOpts) Run(ctx context.Context) error {
129150 return err
130151 }
131152
132- err = operator .NewInstall (installer , atlasStore , credStore , featureValidator , kubeCtl , opts .operatorVersion ).
153+ err = operator .NewInstall (installer , atlasStore , credStore , featureValidator , kubeCtl , opts .operatorVersion , opts . ipAccessList ).
133154 WithNamespace (opts .targetNamespace ).
134155 WithWatchNamespaces (opts .watchNamespace ).
135156 WithWatchProjectName (opts .projectName ).
@@ -164,25 +185,22 @@ The key is scoped to the project when you specify the --projectName option and t
164185 atlas kubernetes operator install
165186
166187 # Install the latest version of the operator targeting Atlas for Government instead of regular commercial Atlas:
167- atlas kubernetes operator install --atlasGov
188+ atlas kubernetes operator install --atlasGov --ipAccessList=<IP_ADDRESS_OR_CIDR>
168189
169190 # Install a specific version of the operator:
170- atlas kubernetes operator install --operatorVersion=1.7.0
191+ atlas kubernetes operator install --ipAccessList=<IP_ADDRESS_OR_CIDR> -- operatorVersion=1.7.0
171192
172193 # Install a specific version of the operator to a namespace and watch only this namespace and a second one:
173- atlas kubernetes operator install --operatorVersion=1.7.0 --targetNamespace=<namespace> --watchNamespace=<namespace>,<secondNamespace>
194+ atlas kubernetes operator install --ipAccessList=<IP_ADDRESS_OR_CIDR> -- operatorVersion=1.7.0 --targetNamespace=<namespace> --watchNamespace=<namespace>,<secondNamespace>
174195
175196 # Install and import all objects from an organization:
176- atlas kubernetes operator install --targetNamespace=<namespace> --orgID <orgID> --import
197+ atlas kubernetes operator install --ipAccessList=<IP_ADDRESS_OR_CIDR> -- targetNamespace=<namespace> --orgID <orgID> --import
177198
178199 # Install and import objects from a specific project:
179- atlas kubernetes operator install --targetNamespace=<namespace> --orgID <orgID> --projectName <project> --import
200+ atlas kubernetes operator install --ipAccessList=<IP_ADDRESS_OR_CIDR> -- targetNamespace=<namespace> --orgID <orgID> --projectName <project> --import
180201
181202 # Install the operator and disable deletion protection:
182- atlas kubernetes operator install --resourceDeletionProtection=false
183-
184- # Install the operator and disable deletion protection for sub-resources (Atlas project integrations, private endpoints, etc.):
185- atlas kubernetes operator install --subresourceDeletionProtection=false` ,
203+ atlas kubernetes operator install --ipAccessList=<IP_ADDRESS_OR_CIDR> --resourceDeletionProtection=false` ,
186204 PreRunE : func (_ * cobra.Command , _ []string ) error {
187205 opts .versionProvider = version .NewOperatorVersion (github .NewClient (nil ))
188206
@@ -192,6 +210,7 @@ The key is scoped to the project when you specify the --projectName option and t
192210 opts .ValidateOperatorVersion ,
193211 opts .ValidateTargetNamespace ,
194212 opts .ValidateWatchNamespace ,
213+ opts .ValidateIpAccessList ,
195214 )
196215 },
197216 RunE : func (cmd * cobra.Command , _ []string ) error {
@@ -213,6 +232,7 @@ The key is scoped to the project when you specify the --projectName option and t
213232 flags .BoolVar (& opts .featureDeletionProtection , flag .OperatorResourceDeletionProtection , true , usage .OperatorResourceDeletionProtection )
214233 flags .BoolVar (& opts .featureSubDeletionProtection , flag .OperatorSubResourceDeletionProtection , true , usage .OperatorSubResourceDeletionProtection )
215234 flags .BoolVar (& opts .configOnly , flag .OperatorConfigOnly , false , usage .OperatorConfigOnly )
235+ flags .StringVar (& opts .ipAccessList , flag .IPAccessList , "" , usage .IPAccessList )
216236
217237 return cmd
218238}
0 commit comments