@@ -57,27 +57,39 @@ func Add(mgr manager.Manager) error {
5757 return fmt .Errorf ("environment variable OPERATOR_NAMESPACE has to be set" )
5858 }
5959
60- sccIsAvailable , err := isSCCAvailable (clientset )
60+ clusterInfo := & network.ClusterInfo {}
61+
62+ openShift4 , err := isRunningOnOpenShift4 (clientset )
63+ if err != nil {
64+ return fmt .Errorf ("failed to check whether running on OpenShift 4: %v" , err )
65+ }
66+ if openShift4 {
67+ log .Printf ("Running on OpenShift 4" )
68+ }
69+ clusterInfo .OpenShift4 = openShift4
70+
71+ sccAvailable , err := isSCCAvailable (clientset )
6172 if err != nil {
6273 return fmt .Errorf ("failed to check for availability of SCC: %v" , err )
6374 }
75+ clusterInfo .SCCAvailable = sccAvailable
6476
65- return add (mgr , newReconciler (mgr , namespace , sccIsAvailable ))
77+ return add (mgr , newReconciler (mgr , namespace , clusterInfo ))
6678}
6779
6880// newReconciler returns a new ReconcileNetworkAddonsConfig
69- func newReconciler (mgr manager.Manager , namespace string , sccIsAvailable bool ) * ReconcileNetworkAddonsConfig {
81+ func newReconciler (mgr manager.Manager , namespace string , clusterInfo * network. ClusterInfo ) * ReconcileNetworkAddonsConfig {
7082 // Status manager is shared between both reconcilers and it is used to update conditions of
7183 // NetworkAddonsConfig.State. NetworkAddonsConfig reconciler updates it with progress of rendering
7284 // and applying of manifests. Pods reconciler updates it with progress of deployed pods.
7385 statusManager := statusmanager .New (mgr .GetClient (), names .OPERATOR_CONFIG )
7486 return & ReconcileNetworkAddonsConfig {
75- client : mgr .GetClient (),
76- scheme : mgr .GetScheme (),
77- namespace : namespace ,
78- podReconciler : newPodReconciler (statusManager ),
79- statusManager : statusManager ,
80- sccIsAvailable : sccIsAvailable ,
87+ client : mgr .GetClient (),
88+ scheme : mgr .GetScheme (),
89+ namespace : namespace ,
90+ podReconciler : newPodReconciler (statusManager ),
91+ statusManager : statusManager ,
92+ clusterInfo : clusterInfo ,
8193 }
8294}
8395
@@ -138,12 +150,12 @@ var _ reconcile.Reconciler = &ReconcileNetworkAddonsConfig{}
138150type ReconcileNetworkAddonsConfig struct {
139151 // This client, initialized using mgr.Client() above, is a split client
140152 // that reads objects from the cache and writes to the apiserver
141- client client.Client
142- scheme * runtime.Scheme
143- namespace string
144- podReconciler * ReconcilePods
145- statusManager * statusmanager.StatusManager
146- sccIsAvailable bool
153+ client client.Client
154+ scheme * runtime.Scheme
155+ namespace string
156+ podReconciler * ReconcilePods
157+ statusManager * statusmanager.StatusManager
158+ clusterInfo * network. ClusterInfo
147159}
148160
149161// Reconcile reads that state of the cluster for a NetworkAddonsConfig object and makes changes based on the state read
@@ -245,7 +257,7 @@ func (r *ReconcileNetworkAddonsConfig) renderObjects(networkAddonsConfig *opv1al
245257 }
246258
247259 // Generate the objects
248- objs , err = network .Render (& networkAddonsConfig .Spec , ManifestPath , openshiftNetworkConfig , r .sccIsAvailable )
260+ objs , err = network .Render (& networkAddonsConfig .Spec , ManifestPath , openshiftNetworkConfig , r .clusterInfo )
249261 if err != nil {
250262 log .Printf ("failed to render: %v" , err )
251263 err = errors .Wrapf (err , "failed to render" )
@@ -327,6 +339,12 @@ func getOpenShiftNetworkConfig(ctx context.Context, c k8sclient.Client) (*osv1.N
327339 return nc , nil
328340}
329341
342+ // Check whether running on OpenShift 4 by looking for operator objects that has been introduced
343+ // only in OpenShift 4
344+ func isRunningOnOpenShift4 (c kubernetes.Interface ) (bool , error ) {
345+ return isResourceAvailable (c , "configs" , "imageregistry.operator.openshift.io" , "v1" )
346+ }
347+
330348func isSCCAvailable (c kubernetes.Interface ) (bool , error ) {
331349 return isResourceAvailable (c , "securitycontextconstraints" , "security.openshift.io" , "v1" )
332350}
0 commit comments