@@ -5,93 +5,84 @@ import (
5
5
"encoding/json"
6
6
"fmt"
7
7
8
- corev1 "k8s.io/api/core/v1"
9
8
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10
9
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
11
- "k8s.io/apimachinery/pkg/util/yaml"
12
10
"k8s.io/client-go/dynamic"
13
- "k8s.io/client-go/informers/core/v1"
14
- coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1"
15
11
16
12
"github.com/openshift/cluster-authentication-operator/pkg/boilerplate/controller"
17
13
"github.com/openshift/cluster-authentication-operator/pkg/boilerplate/operator"
18
14
"github.com/openshift/library-go/pkg/operator/resource/resourcemerge"
19
15
)
20
16
21
17
const (
22
- targetNamespaceName = "kube-system"
23
- targetConfigMap = "cluster-config-v1"
24
18
oldTargetKubeAPIServerOperatorConfig = "instance"
25
19
targetKubeAPIServerOperatorConfig = "cluster"
20
+ targetInfratructureConfig = "cluster"
26
21
)
27
22
28
23
type osinOperator struct {
29
- configMap coreclientv1.ConfigMapsGetter
30
24
oldKubeAPIServerOperatorClient dynamic.ResourceInterface
31
25
kubeAPIServerOperatorClient dynamic.ResourceInterface
26
+ infrastructureConfigClient dynamic.ResourceInterface
32
27
}
33
28
34
- func NewOsinOperator (cmi v1. ConfigMapInformer , cm coreclientv1. ConfigMapsGetter ,
29
+ func NewOsinOperator (
35
30
oldOperatorConfigInformer controller.InformerGetter , oldKubeAPIServerOperatorClient dynamic.ResourceInterface ,
36
- kubeAPIServerOperatorConfigInformer controller.InformerGetter , kubeAPIServerOperatorClient dynamic.ResourceInterface ) operator.Runner {
31
+ kubeAPIServerOperatorConfigInformer controller.InformerGetter , kubeAPIServerOperatorClient dynamic.ResourceInterface ,
32
+ infrastructureConfigInformer controller.InformerGetter , infrastructureConfigClient dynamic.ResourceInterface ) operator.Runner {
37
33
c := & osinOperator {
38
- configMap : cm ,
39
34
oldKubeAPIServerOperatorClient : oldKubeAPIServerOperatorClient ,
40
35
kubeAPIServerOperatorClient : kubeAPIServerOperatorClient ,
36
+ infrastructureConfigClient : infrastructureConfigClient ,
41
37
}
42
38
43
39
return operator .New ("OsinOperator" , c ,
44
- operator .WithInformer (cmi , operator .FilterByNames (targetConfigMap )),
45
40
operator .WithInformer (oldOperatorConfigInformer , operator .FilterByNames (oldTargetKubeAPIServerOperatorConfig , targetKubeAPIServerOperatorConfig ), controller .WithNoSync ()),
46
41
operator .WithInformer (kubeAPIServerOperatorConfigInformer , operator .FilterByNames (oldTargetKubeAPIServerOperatorConfig , targetKubeAPIServerOperatorConfig ), controller .WithNoSync ()),
42
+ operator .WithInformer (infrastructureConfigInformer , operator .FilterByNames (targetInfratructureConfig ), controller .WithNoSync ()),
47
43
)
48
44
}
49
45
50
46
func (c osinOperator ) Key () (metav1.Object , error ) {
51
- return c .configMap . ConfigMaps ( targetNamespaceName ). Get (targetConfigMap , metav1.GetOptions {})
47
+ return c .infrastructureConfigClient . Get (targetInfratructureConfig , metav1.GetOptions {})
52
48
}
53
49
54
50
func (c osinOperator ) Sync (obj metav1.Object ) error {
55
- configMap := obj .(* corev1.ConfigMap )
56
-
57
- installConfig := configMap .Data ["install-config" ]
58
- if len (installConfig ) == 0 {
59
- return fmt .Errorf ("no data: %#v" , configMap )
60
- }
61
- installConfigJSON , err := yaml .ToJSON ([]byte (installConfig ))
51
+ infra := obj .(* unstructured.Unstructured )
52
+ // https://github.com/openshift/api/blob/ea5d05408a95a765d44b5a4b31561b530f0b1f4c/config/v1/types_infrastructure.go#L47
53
+ apiURL , ok , err := unstructured .NestedString (infra .Object , "status" , "apiServerURL" )
62
54
if err != nil {
63
55
return err
64
56
}
65
- ic := & InstallConfig {}
66
- if err := json .Unmarshal (installConfigJSON , ic ); err != nil {
67
- return err
57
+ if ! ok || apiURL == "" {
58
+ return fmt .Errorf ("apiServerURL field not found" )
68
59
}
69
60
70
61
// try all the potential names and resources to update. Eventually we'll be done with the old
71
- updateErr := updateKubeAPIServer (c .oldKubeAPIServerOperatorClient , oldTargetKubeAPIServerOperatorConfig , ic )
62
+ updateErr := updateKubeAPIServer (c .oldKubeAPIServerOperatorClient , oldTargetKubeAPIServerOperatorConfig , apiURL )
72
63
if updateErr == nil {
73
64
return nil
74
65
}
75
66
76
- updateErr = updateKubeAPIServer (c .kubeAPIServerOperatorClient , oldTargetKubeAPIServerOperatorConfig , ic )
67
+ updateErr = updateKubeAPIServer (c .kubeAPIServerOperatorClient , oldTargetKubeAPIServerOperatorConfig , apiURL )
77
68
if updateErr == nil {
78
69
return nil
79
70
}
80
71
81
- updateErr = updateKubeAPIServer (c .oldKubeAPIServerOperatorClient , targetKubeAPIServerOperatorConfig , ic )
72
+ updateErr = updateKubeAPIServer (c .oldKubeAPIServerOperatorClient , targetKubeAPIServerOperatorConfig , apiURL )
82
73
if updateErr == nil {
83
74
return nil
84
75
}
85
76
86
- updateErr = updateKubeAPIServer (c .kubeAPIServerOperatorClient , targetKubeAPIServerOperatorConfig , ic )
77
+ updateErr = updateKubeAPIServer (c .kubeAPIServerOperatorClient , targetKubeAPIServerOperatorConfig , apiURL )
87
78
if updateErr == nil {
88
79
return nil
89
80
}
90
81
91
82
return updateErr
92
83
}
93
84
94
- func updateKubeAPIServer (kubeAPIServerOperatorClient dynamic.ResourceInterface , name string , ic * InstallConfig ) error {
85
+ func updateKubeAPIServer (kubeAPIServerOperatorClient dynamic.ResourceInterface , name , apiURL string ) error {
95
86
apiServerOperatorConfig , err := kubeAPIServerOperatorClient .Get (name , metav1.GetOptions {})
96
87
if err != nil {
97
88
return err
@@ -101,7 +92,6 @@ func updateKubeAPIServer(kubeAPIServerOperatorClient dynamic.ResourceInterface,
101
92
return err
102
93
}
103
94
104
- apiURL := getAPIServerURL (ic )
105
95
expectedOAuthConfig := map [string ]interface {}{
106
96
"spec" : map [string ]interface {}{
107
97
"unsupportedConfigOverrides" : map [string ]interface {}{
0 commit comments