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