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"
@@ -20,14 +21,21 @@ const (
2021 managedNamespace = "openshift-config-managed"
2122)
2223
24+ var (
25+ topLevelMetadataFilePath = []string {"authConfig" , "oauthMetadataFile" }
26+ )
27+
2328// ObserveAuthMetadata fills in authConfig.OauthMetadataFile with the path for a configMap referenced by the authentication
2429// config.
25- func ObserveAuthMetadata (genericListers configobserver.Listers , recorder events.Recorder , existingConfig map [string ]interface {}) (map [string ]interface {}, []error ) {
30+ func ObserveAuthMetadata (genericListers configobserver.Listers , recorder events.Recorder , existingConfig map [string ]interface {}) (ret map [string ]interface {}, _ []error ) {
31+ defer func () {
32+ ret = configobserver .Pruned (ret , topLevelMetadataFilePath )
33+ }()
34+
2635 listers := genericListers .(configobservation.Listers )
2736 errs := []error {}
2837 prevObservedConfig := map [string ]interface {}{}
2938
30- topLevelMetadataFilePath := []string {"authConfig" , "oauthMetadataFile" }
3139 currentMetadataFilePath , _ , err := unstructured .NestedString (existingConfig , topLevelMetadataFilePath ... )
3240 if err != nil {
3341 errs = append (errs , err )
@@ -39,8 +47,9 @@ func ObserveAuthMetadata(genericListers configobserver.Listers, recorder events.
3947 }
4048
4149 observedConfig := map [string ]interface {}{}
42- authConfigNoDefaults , err := listers .AuthConfigLister .Get ("cluster" )
50+ authConfig , err := listers .AuthConfigLister .Get ("cluster" )
4351 if errors .IsNotFound (err ) {
52+ recorder .Eventf ("ObserveAuthMetadataConfigMap" , "authentications.config.openshift.io/cluster: not found" )
4453 klog .Warningf ("authentications.config.openshift.io/cluster: not found" )
4554 return observedConfig , errs
4655 }
@@ -49,34 +58,45 @@ func ObserveAuthMetadata(genericListers configobserver.Listers, recorder events.
4958 return prevObservedConfig , errs
5059 }
5160
52- authConfig := defaultAuthConfig (authConfigNoDefaults )
53-
5461 var (
5562 sourceNamespace string
5663 sourceConfigMap string
57- statusConfigMap string
5864 )
5965
60- 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+ }
6173
62- // TODO: Add a case here for the KeyCloak type.
63- switch {
64- case len (authConfig .Status .IntegratedOAuthMetadata .Name ) > 0 && authConfig .Spec .Type == configv1 .AuthenticationTypeIntegratedOAuth :
65- statusConfigMap = authConfig .Status .IntegratedOAuthMetadata .Name
66- default :
67- klog .V (5 ).Infof ("no integrated oauth metadata configmap observed from status" )
68- }
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
6989
70- // Spec configMap takes precedence over Status.
71- switch {
72- case len ( specConfigMap ) > 0 :
73- sourceConfigMap = specConfigMap
74- sourceNamespace = configNamespace
75- case len ( statusConfigMap ) > 0 :
76- sourceConfigMap = statusConfigMap
77- sourceNamespace = managedNamespace
78- default :
79- klog . V ( 5 ). Infof ( "no authentication config metadata specified" )
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+ }
97+
98+ // no oauth metadata is served; do not set anything as source
99+ // in order to delete the configmap and unset oauthMetadataFile
80100 }
81101
82102 // Sync the user or status-specified configMap to the well-known resting place that corresponds to the oauthMetadataFile path.
@@ -109,13 +129,3 @@ func ObserveAuthMetadata(genericListers configobserver.Listers, recorder events.
109129
110130 return observedConfig , errs
111131}
112-
113- func defaultAuthConfig (authConfig * configv1.Authentication ) * configv1.Authentication {
114- out := authConfig .DeepCopy () // do not mutate informer cache
115-
116- if len (out .Spec .Type ) == 0 {
117- out .Spec .Type = configv1 .AuthenticationTypeIntegratedOAuth
118- }
119-
120- return out
121- }
0 commit comments