|
58 | 58 | ociClusterConcurrency int |
59 | 59 | ociMachineConcurrency int |
60 | 60 | ociMachinePoolConcurrency int |
| 61 | + initOciClientsOnStartup bool |
61 | 62 | ) |
62 | 63 |
|
63 | 64 | const ( |
@@ -115,6 +116,12 @@ func main() { |
115 | 116 | 5, |
116 | 117 | "Number of OciMachinePools to process simultaneously", |
117 | 118 | ) |
| 119 | + flag.BoolVar( |
| 120 | + &initOciClientsOnStartup, |
| 121 | + "init-oci-clients-on-startup", |
| 122 | + true, |
| 123 | + "Initialize OCI clients on startup", |
| 124 | + ) |
118 | 125 |
|
119 | 126 | opts := zap.Options{ |
120 | 127 | Development: true, |
@@ -147,46 +154,48 @@ func main() { |
147 | 154 | setupLog.Error(err, "unable to start manager") |
148 | 155 | os.Exit(1) |
149 | 156 | } |
| 157 | + // Setup the context that's going to be used in controllers and for the manager. |
| 158 | + ctx := ctrl.SetupSignalHandler() |
150 | 159 |
|
151 | | - authConfigDir := os.Getenv(AuthConfigDirectory) |
152 | | - if authConfigDir == "" { |
153 | | - setupLog.Error(err, "auth config directory environment variable is not set") |
154 | | - os.Exit(1) |
155 | | - } |
156 | | - |
157 | | - authConfig, err := config.FromDir(authConfigDir) |
158 | | - if err != nil { |
159 | | - setupLog.Error(err, "invalid auth config file") |
160 | | - os.Exit(1) |
161 | | - } |
| 160 | + var clientProvider *scope.ClientProvider |
| 161 | + var region string |
| 162 | + if initOciClientsOnStartup { |
| 163 | + authConfigDir := os.Getenv(AuthConfigDirectory) |
| 164 | + if authConfigDir == "" { |
| 165 | + setupLog.Error(err, "auth config directory environment variable is not set") |
| 166 | + os.Exit(1) |
| 167 | + } |
162 | 168 |
|
163 | | - setupLog.Info("CAPOCI Version", "version", version.GitVersion) |
164 | | - ociAuthConfigProvider, err := config.NewConfigurationProvider(authConfig) |
165 | | - if err != nil { |
166 | | - setupLog.Error(err, "authentication provider could not be initialised") |
167 | | - os.Exit(1) |
168 | | - } |
| 169 | + authConfig, err := config.FromDir(authConfigDir) |
| 170 | + if err != nil { |
| 171 | + setupLog.Error(err, "invalid auth config file") |
| 172 | + os.Exit(1) |
| 173 | + } |
169 | 174 |
|
170 | | - // Setup the context that's going to be used in controllers and for the manager. |
171 | | - ctx := ctrl.SetupSignalHandler() |
| 175 | + setupLog.Info("CAPOCI Version", "version", version.GitVersion) |
| 176 | + ociAuthConfigProvider, err := config.NewConfigurationProvider(authConfig) |
| 177 | + if err != nil { |
| 178 | + setupLog.Error(err, "authentication provider could not be initialised") |
| 179 | + os.Exit(1) |
| 180 | + } |
172 | 181 |
|
173 | | - region, err := ociAuthConfigProvider.Region() |
174 | | - if err != nil { |
175 | | - setupLog.Error(err, "unable to get OCI region from AuthConfigProvider") |
176 | | - os.Exit(1) |
177 | | - } |
| 182 | + region, err = ociAuthConfigProvider.Region() |
| 183 | + if err != nil { |
| 184 | + setupLog.Error(err, "unable to get OCI region from AuthConfigProvider") |
| 185 | + os.Exit(1) |
| 186 | + } |
178 | 187 |
|
179 | | - clientProvider, err := scope.NewClientProvider(ociAuthConfigProvider) |
180 | | - if err != nil { |
181 | | - setupLog.Error(err, "unable to create OCI ClientProvider") |
182 | | - os.Exit(1) |
183 | | - } |
184 | | - _, err = clientProvider.GetOrBuildClient(region) |
185 | | - if err != nil { |
186 | | - setupLog.Error(err, "authentication provider could not be initialised") |
187 | | - os.Exit(1) |
| 188 | + clientProvider, err = scope.NewClientProvider(ociAuthConfigProvider) |
| 189 | + if err != nil { |
| 190 | + setupLog.Error(err, "unable to create OCI ClientProvider") |
| 191 | + os.Exit(1) |
| 192 | + } |
| 193 | + _, err = clientProvider.GetOrBuildClient(region) |
| 194 | + if err != nil { |
| 195 | + setupLog.Error(err, "authentication provider could not be initialised") |
| 196 | + os.Exit(1) |
| 197 | + } |
188 | 198 | } |
189 | | - |
190 | 199 | if err = (&controllers.OCIClusterReconciler{ |
191 | 200 | Client: mgr.GetClient(), |
192 | 201 | Scheme: mgr.GetScheme(), |
|
0 commit comments