Skip to content

Commit 535d6ef

Browse files
Add ability to disable oci client init on startup (#243)
* Add option to disable OCI client init on startup
1 parent db4d5fc commit 535d6ef

File tree

5 files changed

+67
-34
lines changed

5 files changed

+67
-34
lines changed

cloud/util/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ func InitClientsAndRegion(ctx context.Context, client client.Client, defaultRegi
158158
} else {
159159
clientProvider = defaultClientProvider
160160
}
161+
if clientProvider == nil {
162+
return nil, "", scope.OCIClients{}, errors.New("OCI authentication credentials could not be retrieved from pod or cluster level," +
163+
"please install Cluster API Provider for OCI with OCI authentication credentials or set Cluster Identity in the OCICluster")
164+
}
161165
// Region set at cluster takes highest precedence
162166
if len(clusterAccessor.GetRegion()) > 0 {
163167
clusterRegion = clusterAccessor.GetRegion()

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ spec:
3030
- "--feature-gates=MachinePool=${EXP_MACHINE_POOL:=false},OKE=${EXP_OKE:=false}"
3131
- "--metrics-bind-address=127.0.0.1:8080"
3232
- "--logging-format=${LOG_FORMAT:=text}"
33+
- "--init-oci-clients-on-startup=${INIT_OCI_CLIENTS_ON_STARTUP:=true}"
3334
image: controller:latest
3435
name: manager
3536
securityContext:

docs/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- [Provision a PVC on the File Storage Service](./gs/pvc-fss.md)
3030
- [Customize worker nodes](./gs/customize-worker-node.md)
3131
- [Multi Tenancy](./gs/multi-tenancy.md)
32+
- [Advanced Options](./gs/advanced.md)
3233
- [Networking Guide](./networking/networking.md)
3334
- [Default Network Infrastructure](./networking/infrastructure.md)
3435
- [Using Calico](./networking/calico.md)

docs/src/gs/advanced.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Advanced Options
2+
3+
## Disable OCI Client initialization on startup
4+
5+
CAPOCI supports setting OCI principals at [cluster level][cluster-identity], hence CAPOCI can be
6+
installed without providing OCI user credentials. The following environment variable need to be exported
7+
to install CAPOCI without providing any OCI credentials.
8+
9+
```shell
10+
export INIT_OCI_CLIENTS_ON_STARTUP=false
11+
```
12+
13+
If the above setting is used, and [Cluster Identity][cluster-identity] is not used, the OCICluster will
14+
go into error state, and the following error will show up in the CAPOCI pod logs.
15+
16+
`OCI authentication credentials could not be retrieved from pod or cluster level,please install Cluster API Provider for OCI with OCI authentication credentials or set Cluster Identity in the OCICluster`
17+
18+
[cluster-identity]: ./multi-tenancy.md

main.go

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var (
5757
ociClusterConcurrency int
5858
ociMachineConcurrency int
5959
ociMachinePoolConcurrency int
60+
initOciClientsOnStartup bool
6061
)
6162

6263
const (
@@ -112,6 +113,12 @@ func main() {
112113
5,
113114
"Number of OciMachinePools to process simultaneously",
114115
)
116+
flag.BoolVar(
117+
&initOciClientsOnStartup,
118+
"init-oci-clients-on-startup",
119+
true,
120+
"Initialize OCI clients on startup",
121+
)
115122

116123
opts := zap.Options{
117124
Development: true,
@@ -144,46 +151,48 @@ func main() {
144151
setupLog.Error(err, "unable to start manager")
145152
os.Exit(1)
146153
}
154+
// Setup the context that's going to be used in controllers and for the manager.
155+
ctx := ctrl.SetupSignalHandler()
147156

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+
}
159165

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+
}
166171

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+
}
169178

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+
}
175184

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+
}
185195
}
186-
187196
if err = (&controllers.OCIClusterReconciler{
188197
Client: mgr.GetClient(),
189198
Scheme: mgr.GetScheme(),

0 commit comments

Comments
 (0)