@@ -11,6 +11,7 @@ import (
11
11
configv1client "github.com/openshift/client-go/config/clientset/versioned"
12
12
configinformers "github.com/openshift/client-go/config/informers/externalversions"
13
13
configinformersv1 "github.com/openshift/client-go/config/informers/externalversions/config/v1"
14
+ applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
14
15
"github.com/openshift/cluster-kube-controller-manager-operator/bindata"
15
16
"github.com/openshift/cluster-kube-controller-manager-operator/pkg/operator/certrotationcontroller"
16
17
"github.com/openshift/cluster-kube-controller-manager-operator/pkg/operator/configobservation/configobservercontroller"
@@ -36,7 +37,9 @@ import (
36
37
policyv1 "k8s.io/api/policy/v1"
37
38
"k8s.io/apimachinery/pkg/api/errors"
38
39
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
40
+ "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
39
41
"k8s.io/apimachinery/pkg/labels"
42
+ "k8s.io/apimachinery/pkg/runtime"
40
43
"k8s.io/client-go/kubernetes"
41
44
"k8s.io/klog/v2"
42
45
"k8s.io/utils/ptr"
@@ -64,7 +67,13 @@ func RunOperator(ctx context.Context, cc *controllercmd.ControllerContext) error
64
67
"openshift-infra" ,
65
68
)
66
69
67
- operatorClient , dynamicInformers , err := genericoperatorclient .NewStaticPodOperatorClient (cc .KubeConfig , operatorv1 .GroupVersion .WithResource ("kubecontrollermanagers" ))
70
+ operatorClient , dynamicInformers , err := genericoperatorclient .NewStaticPodOperatorClient (
71
+ cc .KubeConfig ,
72
+ operatorv1 .GroupVersion .WithResource ("kubecontrollermanagers" ),
73
+ operatorv1 .GroupVersion .WithKind ("KubeControllerManager" ),
74
+ ExtractStaticPodOperatorSpec ,
75
+ ExtractStaticPodOperatorStatus ,
76
+ )
68
77
if err != nil {
69
78
return err
70
79
}
@@ -375,3 +384,34 @@ func newPlatformMatcherFn(platform configv1.PlatformType, infraInformer configin
375
384
return infraData .Status .PlatformStatus .Type == platform , true , nil
376
385
}
377
386
}
387
+
388
+ func ExtractStaticPodOperatorSpec (obj * unstructured.Unstructured , fieldManager string ) (* applyoperatorv1.StaticPodOperatorSpecApplyConfiguration , error ) {
389
+ castObj := & operatorv1.KubeControllerManager {}
390
+ if err := runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , castObj ); err != nil {
391
+ return nil , fmt .Errorf ("unable to convert to KubeControllerManager: %w" , err )
392
+ }
393
+ ret , err := applyoperatorv1 .ExtractKubeControllerManager (castObj , fieldManager )
394
+ if err != nil {
395
+ return nil , fmt .Errorf ("unable to extract fields for %q: %w" , fieldManager , err )
396
+ }
397
+ if ret .Spec == nil {
398
+ return nil , nil
399
+ }
400
+ return & ret .Spec .StaticPodOperatorSpecApplyConfiguration , nil
401
+ }
402
+
403
+ func ExtractStaticPodOperatorStatus (obj * unstructured.Unstructured , fieldManager string ) (* applyoperatorv1.StaticPodOperatorStatusApplyConfiguration , error ) {
404
+ castObj := & operatorv1.KubeControllerManager {}
405
+ if err := runtime .DefaultUnstructuredConverter .FromUnstructured (obj .Object , castObj ); err != nil {
406
+ return nil , fmt .Errorf ("unable to convert to KubeControllerManager: %w" , err )
407
+ }
408
+ ret , err := applyoperatorv1 .ExtractKubeControllerManagerStatus (castObj , fieldManager )
409
+ if err != nil {
410
+ return nil , fmt .Errorf ("unable to extract fields for %q: %w" , fieldManager , err )
411
+ }
412
+
413
+ if ret .Status == nil {
414
+ return nil , nil
415
+ }
416
+ return & ret .Status .StaticPodOperatorStatusApplyConfiguration , nil
417
+ }
0 commit comments