88
99 configv1 "github.com/openshift/api/config/v1"
1010 "github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/configobservation"
11+ "github.com/openshift/cluster-kube-apiserver-operator/pkg/operator/operatorclient"
1112 "github.com/openshift/library-go/pkg/operator/configobserver"
1213 "github.com/openshift/library-go/pkg/operator/events"
1314 "github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
@@ -46,8 +47,9 @@ func ObserveAuthMetadata(genericListers configobserver.Listers, recorder events.
4647 }
4748
4849 observedConfig := map [string ]interface {}{}
49- authConfigNoDefaults , err := listers .AuthConfigLister .Get ("cluster" )
50+ authConfig , err := listers .AuthConfigLister .Get ("cluster" )
5051 if errors .IsNotFound (err ) {
52+ recorder .Eventf ("ObserveAuthMetadataConfigMap" , "authentications.config.openshift.io/cluster: not found" )
5153 klog .Warningf ("authentications.config.openshift.io/cluster: not found" )
5254 return observedConfig , errs
5355 }
@@ -56,34 +58,45 @@ func ObserveAuthMetadata(genericListers configobserver.Listers, recorder events.
5658 return prevObservedConfig , errs
5759 }
5860
59- authConfig := defaultAuthConfig (authConfigNoDefaults )
60-
6161 var (
6262 sourceNamespace string
6363 sourceConfigMap string
64- statusConfigMap string
6564 )
6665
67- specConfigMap := authConfig .Spec .OAuthMetadata .Name
66+ switch authConfig .Spec .Type {
67+ case configv1 .AuthenticationTypeIntegratedOAuth , "" :
68+ specConfigMap := authConfig .Spec .OAuthMetadata .Name
69+ statusConfigMap := authConfig .Status .IntegratedOAuthMetadata .Name
70+ if len (statusConfigMap ) == 0 {
71+ klog .V (5 ).Infof ("no integrated oauth metadata configmap observed from status" )
72+ }
6873
69- // TODO: Add a case here for the KeyCloak type.
70- switch {
71- case len (authConfig .Status .IntegratedOAuthMetadata .Name ) > 0 && authConfig .Spec .Type == configv1 .AuthenticationTypeIntegratedOAuth :
72- statusConfigMap = authConfig .Status .IntegratedOAuthMetadata .Name
73- default :
74- klog .V (5 ).Infof ("no integrated oauth metadata configmap observed from status" )
75- }
74+ // Spec configMap takes precedence over Status.
75+ switch {
76+ case len (specConfigMap ) > 0 :
77+ sourceConfigMap = specConfigMap
78+ sourceNamespace = configNamespace
79+ case len (statusConfigMap ) > 0 :
80+ sourceConfigMap = statusConfigMap
81+ sourceNamespace = managedNamespace
82+ default :
83+ klog .V (5 ).Infof ("no authentication config metadata specified" )
84+ }
85+
86+ case configv1 .AuthenticationTypeNone :
87+ // no oauth metadata is served; do not set anything as source
88+ // in order to delete the configmap and unset oauthMetadataFile
89+
90+ case configv1 .AuthenticationTypeOIDC :
91+ if _ , err := listers .ConfigmapLister_ .ConfigMaps (operatorclient .TargetNamespace ).Get (AuthConfigCMName ); errors .IsNotFound (err ) {
92+ // auth-config does not exist in target namespace yet; do not remove oauth metadata until it's there
93+ return prevObservedConfig , errs
94+ } else if err != nil {
95+ return prevObservedConfig , append (errs , err )
96+ }
7697
77- // Spec configMap takes precedence over Status.
78- switch {
79- case len (specConfigMap ) > 0 :
80- sourceConfigMap = specConfigMap
81- sourceNamespace = configNamespace
82- case len (statusConfigMap ) > 0 :
83- sourceConfigMap = statusConfigMap
84- sourceNamespace = managedNamespace
85- default :
86- klog .V (5 ).Infof ("no authentication config metadata specified" )
98+ // no oauth metadata is served; do not set anything as source
99+ // in order to delete the configmap and unset oauthMetadataFile
87100 }
88101
89102 // Sync the user or status-specified configMap to the well-known resting place that corresponds to the oauthMetadataFile path.
@@ -116,13 +129,3 @@ func ObserveAuthMetadata(genericListers configobserver.Listers, recorder events.
116129
117130 return observedConfig , errs
118131}
119-
120- func defaultAuthConfig (authConfig * configv1.Authentication ) * configv1.Authentication {
121- out := authConfig .DeepCopy () // do not mutate informer cache
122-
123- if len (out .Spec .Type ) == 0 {
124- out .Spec .Type = configv1 .AuthenticationTypeIntegratedOAuth
125- }
126-
127- return out
128- }
0 commit comments