Skip to content

Commit 3d01ffb

Browse files
Always align documented values from Authentication (#970)
Originating issue: [IBMPrivateCloud/roadmap#65335](https://github.ibm.com/IBMPrivateCloud/roadmap/issues/65335) Always updates the following values in the `platform-auth-idp` in order to better support various backup and restore behaviors: * "ROKS_URL" * "ROKS_USER_PREFIX" * "ROKS_ENABLED" * "BOOTSTRAP_USERID" * "CLAIMS_SUPPORTED" * "CLAIMS_MAP" * "SCOPE_CLAIM" * "NONCE_ENABLED" * "PREFERRED_LOGIN" * "OIDC_ISSUER_URL" * "PROVIDER_ISSUER_URL" * "CLUSTER_NAME" --------- Signed-off-by: Rob Hundley <[email protected]> Co-authored-by: Tirumala Mannaru <[email protected]>
1 parent 10295c4 commit 3d01ffb

File tree

2 files changed

+104
-36
lines changed

2 files changed

+104
-36
lines changed

controllers/operator/configmap.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@ func updatesValuesWhen(matches matcherFunc, keys ...string) (fn func(*corev1.Con
281281
}
282282
}
283283

284+
func updatesAlways(keys ...string) (fn func(*corev1.ConfigMap, *corev1.ConfigMap) bool) {
285+
return func(observed, updates *corev1.ConfigMap) bool {
286+
return updateFields(observed, updates, keys...)
287+
}
288+
}
289+
284290
func replaceOIDCClientRegistrationJob(ctx context.Context, cl client.Client, authCR *operatorv1alpha1.Authentication) (err error) {
285291
job := &batchv1.Job{
286292
ObjectMeta: metav1.ObjectMeta{
@@ -400,6 +406,20 @@ func updateOAuthClientConfigMap(observed, generated *corev1.ConfigMap) (updated
400406

401407
func updatePlatformAuthIDP(observed, generated *corev1.ConfigMap) (updated bool, err error) {
402408
updateFns := []func(*corev1.ConfigMap, *corev1.ConfigMap) bool{
409+
updatesAlways(
410+
"ROKS_URL",
411+
"ROKS_USER_PREFIX",
412+
"ROKS_ENABLED",
413+
"BOOTSTRAP_USERID",
414+
"CLAIMS_SUPPORTED",
415+
"CLAIMS_MAP",
416+
"SCOPE_CLAIM",
417+
"NONCE_ENABLED",
418+
"PREFERRED_LOGIN",
419+
"OIDC_ISSUER_URL",
420+
"PROVIDER_ISSUER_URL",
421+
"CLUSTER_NAME",
422+
),
403423
updatesValuesWhen(observedKeyValueSetTo("OS_TOKEN_LENGTH", "45"),
404424
"OS_TOKEN_LENGTH"),
405425
updatesValuesWhen(observedKeyValueContains("IDENTITY_MGMT_URL", "127.0.0.1"),
@@ -415,15 +435,6 @@ func updatePlatformAuthIDP(observed, generated *corev1.ConfigMap) (updated bool,
415435
"IDENTITY_PROVIDER_URL"),
416436
updatesValuesWhen(not(observedKeySet("LDAP_RECURSIVE_SEARCH")),
417437
"LDAP_RECURSIVE_SEARCH"),
418-
updatesValuesWhen(not(observedKeySet("CLAIMS_SUPPORTED")),
419-
"CLAIMS_SUPPORTED",
420-
"CLAIMS_MAP",
421-
"SCOPE_CLAIM",
422-
"BOOTSTRAP_USERID"),
423-
updatesValuesWhen(not(observedKeySet("PROVIDER_ISSUER_URL")),
424-
"PROVIDER_ISSUER_URL"),
425-
updatesValuesWhen(not(observedKeySet("PREFERRED_LOGIN")),
426-
"PREFERRED_LOGIN"),
427438
updatesValuesWhen(not(observedKeyValueSetTo("DEFAULT_LOGIN", generated.Data["DEFAULT_LOGIN"])),
428439
"DEFAULT_LOGIN"),
429440
updatesValuesWhen(not(observedKeyValueSetTo("MASTER_HOST", generated.Data["MASTER_HOST"])),
@@ -462,10 +473,6 @@ func updatePlatformAuthIDP(observed, generated *corev1.ConfigMap) (updated bool,
462473
"LDAP_CTX_POOL_PREFERREDSIZE"),
463474
}
464475

465-
if v, ok := generated.Data["ROKS_URL"]; ok {
466-
updateFns = append(updateFns, updatesValuesWhen(
467-
not(observedKeyValueSetTo("ROKS_URL", v)), "ROKS_URL"))
468-
}
469476
if v, ok := generated.Data["IS_OPENSHIFT_ENV"]; ok {
470477
updateFns = append(updateFns, updatesValuesWhen(
471478
not(observedKeyValueSetTo("IS_OPENSHIFT_ENV", v)), "IS_OPENSHIFT_ENV"))
@@ -520,6 +527,8 @@ func generateAuthIdpConfigMap(ctx context.Context, cl client.Client, authCR *ope
520527
var desiredRoksUrl string
521528
if authCR.Spec.Config.ROKSEnabled && !isOSEnv {
522529
reqLogger.Info(".spec.config.roksEnabled is set to true, but workload does not appear to be running on OpenShift; disabling in ConfigMap")
530+
} else if authCR.Spec.Config.ROKSEnabled && authCR.Spec.Config.ROKSURL != "https://roks.domain.name:443" {
531+
desiredRoksUrl = authCR.Spec.Config.ROKSURL
523532
} else if authCR.Spec.Config.ROKSEnabled {
524533
if desiredRoksUrl, err = readROKSURL(ctx); err != nil {
525534
reqLogger.Error(err, "Failed to get issuer URL")

controllers/operator/configmap_test.go

Lines changed: 82 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -547,31 +547,10 @@ var _ = Describe("ConfigMap handling", func() {
547547
"LDAP_RECURSIVE_SEARCH",
548548
[]string{"LDAP_RECURSIVE_SEARCH"},
549549
},
550-
{
551-
"CLAIMS_SUPPORTED",
552-
[]string{
553-
"CLAIMS_SUPPORTED",
554-
"CLAIMS_MAP",
555-
"SCOPE_CLAIM",
556-
"BOOTSTRAP_USERID",
557-
},
558-
},
559550
{
560551
"DEFAULT_LOGIN",
561552
[]string{"DEFAULT_LOGIN"},
562553
},
563-
{
564-
"PROVIDER_ISSUER_URL",
565-
[]string{
566-
"PROVIDER_ISSUER_URL",
567-
},
568-
},
569-
{
570-
"PREFERRED_LOGIN",
571-
[]string{
572-
"PREFERRED_LOGIN",
573-
},
574-
},
575554
{
576555
"DB_CONNECT_TIMEOUT",
577556
[]string{
@@ -654,7 +633,46 @@ var _ = Describe("ConfigMap handling", func() {
654633
}
655634

656635
for _, test := range updateOnNotSetKeys {
657-
observed := getObserved()
636+
observed := &corev1.ConfigMap{}
637+
Expect(generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, observed)).
638+
To(Succeed())
639+
generated := &corev1.ConfigMap{}
640+
err := generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, generated)
641+
Expect(err).NotTo(HaveOccurred())
642+
updated, err = updatePlatformAuthIDP(observed, generated)
643+
Expect(err).ToNot(HaveOccurred())
644+
Expect(updated).To(BeFalse())
645+
setDummyData(test.primaryKey, test.keys, observed)
646+
updated, err = updatePlatformAuthIDP(observed, generated)
647+
Expect(err).NotTo(HaveOccurred())
648+
Expect(updated).To(BeTrue())
649+
for _, k := range test.keys {
650+
Expect(observed.Data[k]).To(Equal(generated.Data[k]))
651+
}
652+
}
653+
})
654+
655+
It("sets fields when the values do not match the expected value", func() {
656+
updateOnNotUpToDate := []struct {
657+
primaryKey string
658+
keys []string
659+
}{
660+
{
661+
"DEFAULT_LOGIN",
662+
[]string{"DEFAULT_LOGIN"},
663+
},
664+
}
665+
666+
setDummyData := func(pkey string, keys []string, o *corev1.ConfigMap) {
667+
dummyValue := "dummy"
668+
for _, k := range keys {
669+
o.Data[k] = dummyValue
670+
}
671+
}
672+
for _, test := range updateOnNotUpToDate {
673+
observed := &corev1.ConfigMap{}
674+
Expect(generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, observed)).
675+
To(Succeed())
658676
generated := &corev1.ConfigMap{}
659677
err := generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, generated)
660678
Expect(err).NotTo(HaveOccurred())
@@ -694,7 +712,9 @@ var _ = Describe("ConfigMap handling", func() {
694712
})
695713

696714
It("replaces value in OS_TOKEN_LENGTH only when it is set to 45", func() {
697-
observed := getObserved()
715+
observed := &corev1.ConfigMap{}
716+
Expect(generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, observed)).
717+
To(Succeed())
698718
// Set the keys in observed to contain localhost IP
699719
k := "OS_TOKEN_LENGTH"
700720
observed.Data[k] = "24"
@@ -711,6 +731,45 @@ var _ = Describe("ConfigMap handling", func() {
711731
Expect(updated).To(BeTrue())
712732
Expect(observed.Data[k]).To(Equal(generated.Data[k]))
713733
})
734+
735+
It("always replaces certain values if they differ", func() {
736+
updateAlways := []string{
737+
"ROKS_URL",
738+
"ROKS_USER_PREFIX",
739+
"ROKS_ENABLED",
740+
"BOOTSTRAP_USERID",
741+
"CLAIMS_SUPPORTED",
742+
"CLAIMS_MAP",
743+
"SCOPE_CLAIM",
744+
"NONCE_ENABLED",
745+
"PREFERRED_LOGIN",
746+
"OIDC_ISSUER_URL",
747+
"PROVIDER_ISSUER_URL",
748+
"CLUSTER_NAME",
749+
}
750+
751+
setDummyData := func(k string, o *corev1.ConfigMap) {
752+
dummyValue := "dummy"
753+
o.Data[k] = dummyValue
754+
}
755+
for _, test := range updateAlways {
756+
observed := getObserved()
757+
Expect(generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, observed)).
758+
To(Succeed())
759+
generated := &corev1.ConfigMap{}
760+
err := generateAuthIdpConfigMap(ctx, r.Client, authCR, ibmcloudClusterInfo, generated)
761+
Expect(err).NotTo(HaveOccurred())
762+
updated, err = updatePlatformAuthIDP(observed, generated)
763+
Expect(err).ToNot(HaveOccurred())
764+
Expect(updated).To(BeFalse())
765+
setDummyData(test, observed)
766+
Expect(observed.Data[test]).To(Equal("dummy"))
767+
updated, err = updatePlatformAuthIDP(observed, generated)
768+
Expect(err).NotTo(HaveOccurred())
769+
Expect(updated).To(BeTrue())
770+
Expect(observed.Data[test]).To(Equal(generated.Data[test]))
771+
}
772+
})
714773
})
715774

716775
Describe("oauth-client-map handling", func() {

0 commit comments

Comments
 (0)