@@ -28,6 +28,7 @@ import (
28
28
corev1 "k8s.io/api/core/v1"
29
29
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
30
30
"k8s.io/apimachinery/pkg/types"
31
+ "k8s.io/utils/ptr"
31
32
ctrl "sigs.k8s.io/controller-runtime"
32
33
"sigs.k8s.io/controller-runtime/pkg/builder"
33
34
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -36,8 +37,9 @@ import (
36
37
"sigs.k8s.io/controller-runtime/pkg/predicate"
37
38
)
38
39
39
- // BootStrapReconciler handles modifications to the Authentication CR before it is reconciled by the
40
- // main Authentication controller
40
+ // BootStrapReconciler handles modifications to the Authentication CR before it
41
+ // is reconciled by the main Authentication controller; this is meant to handle
42
+ // edge cases that are encountered during upgrades.
41
43
type BootstrapReconciler struct {
42
44
client.Client
43
45
}
@@ -105,10 +107,13 @@ func (r *BootstrapReconciler) makeAuthenticationCorrections(ctx context.Context,
105
107
// writeConfigurationsToAuthenticationCR copies values from the
106
108
// platform-auth-idp ConfigMap to the Authentication CR.
107
109
func (r * BootstrapReconciler ) writeConfigurationsToAuthenticationCR (ctx context.Context , authCR * operatorv1alpha1.Authentication ) (err error ) {
110
+ log := logf .FromContext (ctx , "ConfigMap.Name" , "platform-auth-idp" ).V (1 )
108
111
platformAuthIDPCM := & corev1.ConfigMap {}
109
112
if err = r .Get (ctx , types.NamespacedName {Name : "platform-auth-idp" , Namespace : authCR .Namespace }, platformAuthIDPCM ); k8sErrors .IsNotFound (err ) {
113
+ log .Info ("ConfigMap not found" )
110
114
return nil
111
115
} else if err != nil {
116
+ log .Error (err , "Failed to get ConfigMap" )
112
117
return fmt .Errorf ("failed to get ConfigMap: %w" , err )
113
118
}
114
119
keys := map [string ]any {
@@ -129,23 +134,50 @@ func (r *BootstrapReconciler) writeConfigurationsToAuthenticationCR(ctx context.
129
134
"IBM_CLOUD_SAAS" : & authCR .Spec .Config .IBMCloudSaas ,
130
135
"SAAS_CLIENT_REDIRECT_URL" : & authCR .Spec .Config .SaasClientRedirectUrl ,
131
136
"ATTR_MAPPING_FROM_CONFIG" : & authCR .Spec .Config .AttrMappingFromConfig ,
137
+ "AUDIT_URL" : & authCR .Spec .Config .AuditUrl ,
138
+ "AUDIT_SECRET" : & authCR .Spec .Config .AuditSecret ,
132
139
}
133
140
134
141
for key , crField := range keys {
142
+ keyLog := log .WithValues ("key" , key )
135
143
cmValue , ok := platformAuthIDPCM .Data [key ]
136
144
if ! ok {
145
+ keyLog .Info ("Key not found; continuing" )
137
146
continue
138
147
}
148
+ keyLog .Info ("Key found" , "value" , cmValue )
139
149
switch crValue := crField .(type ) {
150
+
140
151
case * string :
141
- if * crValue != cmValue {
152
+ keyLog .Info ("Value type is string" )
153
+ if crValue != nil && * crValue != cmValue {
154
+ keyLog .Info ("Value of property on CR does not match value for key in ConfigMap" )
142
155
* crValue = cmValue
156
+ } else if crValue != nil {
157
+ keyLog .Info ("Values match" )
158
+ }
159
+ case * * string :
160
+ keyLog .Info ("Value type is optional string" )
161
+ if * crValue == nil {
162
+ keyLog .Info ("Property is not set on CR" )
163
+ * crValue = ptr .To (cmValue )
164
+ } else if * * crValue != cmValue {
165
+ keyLog .Info ("Value of property on CR does not match value for key in ConfigMap" )
166
+ * crValue = ptr .To (cmValue )
167
+ } else {
168
+ keyLog .Info ("Values match" )
143
169
}
144
170
case * bool :
171
+ keyLog .Info ("Value type is bool" )
145
172
cmValueBool , _ := strconv .ParseBool (cmValue )
146
- if * crValue != cmValueBool {
173
+ if crValue != nil && * crValue != cmValueBool {
174
+ keyLog .Info ("Value of property on CR does not match value for key in ConfigMap" )
147
175
* crValue = cmValueBool
176
+ } else if crValue != nil {
177
+ keyLog .Info ("Values match" )
148
178
}
179
+ default :
180
+ keyLog .Info ("Value type is unknown; skipping" )
149
181
}
150
182
}
151
183
0 commit comments