@@ -12,11 +12,8 @@ import (
12
12
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
13
13
"k8s.io/apimachinery/pkg/util/wait"
14
14
batchv1informers "k8s.io/client-go/informers/batch/v1"
15
- corev1informers "k8s.io/client-go/informers/core/v1"
16
15
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
17
16
batchv1listers "k8s.io/client-go/listers/batch/v1"
18
- corev1listers "k8s.io/client-go/listers/core/v1"
19
- restclient "k8s.io/client-go/rest"
20
17
"k8s.io/client-go/tools/cache"
21
18
"k8s.io/client-go/util/workqueue"
22
19
"k8s.io/klog/v2"
@@ -26,11 +23,9 @@ import (
26
23
configlisters "github.com/openshift/client-go/config/listers/config/v1"
27
24
imageregistryv1informers "github.com/openshift/client-go/imageregistry/informers/externalversions/imageregistry/v1"
28
25
imageregistryv1listers "github.com/openshift/client-go/imageregistry/listers/imageregistry/v1"
29
- "github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
30
26
"github.com/openshift/library-go/pkg/operator/v1helpers"
31
27
32
28
"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
33
- "github.com/openshift/cluster-image-registry-operator/pkg/resource"
34
29
"github.com/openshift/cluster-image-registry-operator/pkg/storage/util"
35
30
)
36
31
@@ -39,45 +34,26 @@ type AzurePathFixController struct {
39
34
operatorClient v1helpers.OperatorClient
40
35
jobLister batchv1listers.JobNamespaceLister
41
36
imageRegistryConfigLister imageregistryv1listers.ConfigLister
42
- secretLister corev1listers.SecretNamespaceLister
43
- podLister corev1listers.PodNamespaceLister
44
37
infrastructureLister configlisters.InfrastructureLister
45
- proxyLister configlisters.ProxyLister
46
- openshiftConfigLister corev1listers.ConfigMapNamespaceLister
47
- kubeconfig * restclient.Config
48
38
49
39
cachesToSync []cache.InformerSynced
50
40
queue workqueue.RateLimitingInterface
51
-
52
- featureGateAccessor featuregates.FeatureGateAccess
53
41
}
54
42
55
43
func NewAzurePathFixController (
56
- kubeconfig * restclient.Config ,
57
44
batchClient batchv1client.BatchV1Interface ,
58
45
operatorClient v1helpers.OperatorClient ,
59
46
jobInformer batchv1informers.JobInformer ,
60
47
imageRegistryConfigInformer imageregistryv1informers.ConfigInformer ,
61
48
infrastructureInformer configv1informers.InfrastructureInformer ,
62
- secretInformer corev1informers.SecretInformer ,
63
- proxyInformer configv1informers.ProxyInformer ,
64
- openshiftConfigInformer corev1informers.ConfigMapInformer ,
65
- podInformer corev1informers.PodInformer ,
66
- featureGateAccessor featuregates.FeatureGateAccess ,
67
49
) (* AzurePathFixController , error ) {
68
50
c := & AzurePathFixController {
69
51
batchClient : batchClient ,
70
52
operatorClient : operatorClient ,
71
53
jobLister : jobInformer .Lister ().Jobs (defaults .ImageRegistryOperatorNamespace ),
72
54
imageRegistryConfigLister : imageRegistryConfigInformer .Lister (),
73
55
infrastructureLister : infrastructureInformer .Lister (),
74
- secretLister : secretInformer .Lister ().Secrets (defaults .ImageRegistryOperatorNamespace ),
75
- podLister : podInformer .Lister ().Pods (defaults .ImageRegistryOperatorNamespace ),
76
- proxyLister : proxyInformer .Lister (),
77
- openshiftConfigLister : openshiftConfigInformer .Lister ().ConfigMaps (defaults .OpenShiftConfigNamespace ),
78
- kubeconfig : kubeconfig ,
79
56
queue : workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), "AzurePathFixController" ),
80
- featureGateAccessor : featureGateAccessor ,
81
57
}
82
58
83
59
if _ , err := jobInformer .Informer ().AddEventHandler (c .eventHandler ()); err != nil {
@@ -90,31 +66,10 @@ func NewAzurePathFixController(
90
66
}
91
67
c .cachesToSync = append (c .cachesToSync , imageRegistryConfigInformer .Informer ().HasSynced )
92
68
93
- if _ , err := infrastructureInformer .Informer ().AddEventHandler (c .eventHandler ()); err != nil {
94
- return nil , err
95
- }
69
+ // we need the infra only to check for PlatformStatus.Type, which isn't
70
+ // expected to change, so we don't need to add an event handler.
96
71
c .cachesToSync = append (c .cachesToSync , infrastructureInformer .Informer ().HasSynced )
97
72
98
- if _ , err := secretInformer .Informer ().AddEventHandler (c .eventHandler ()); err != nil {
99
- return nil , err
100
- }
101
- c .cachesToSync = append (c .cachesToSync , secretInformer .Informer ().HasSynced )
102
-
103
- if _ , err := podInformer .Informer ().AddEventHandler (c .eventHandler ()); err != nil {
104
- return nil , err
105
- }
106
- c .cachesToSync = append (c .cachesToSync , podInformer .Informer ().HasSynced )
107
-
108
- if _ , err := proxyInformer .Informer ().AddEventHandler (c .eventHandler ()); err != nil {
109
- return nil , err
110
- }
111
- c .cachesToSync = append (c .cachesToSync , proxyInformer .Informer ().HasSynced )
112
-
113
- if _ , err := openshiftConfigInformer .Informer ().AddEventHandler (c .eventHandler ()); err != nil {
114
- return nil , err
115
- }
116
- c .cachesToSync = append (c .cachesToSync , openshiftConfigInformer .Informer ().HasSynced )
117
-
118
73
// bootstrap the job if it doesn't exist
119
74
c .queue .Add ("instance" )
120
75
@@ -163,6 +118,8 @@ func (c *AzurePathFixController) processNextWorkItem() bool {
163
118
}
164
119
165
120
func (c * AzurePathFixController ) sync () error {
121
+ ctx := context .TODO ()
122
+
166
123
// this controller was made to run specifically on Azure,
167
124
// so if we detect a different cloud, skip it.
168
125
infra , err := util .GetInfrastructure (c .infrastructureLister )
@@ -178,31 +135,13 @@ func (c *AzurePathFixController) sync() error {
178
135
return err
179
136
}
180
137
181
- azureStorage := imageRegistryConfig .Status .Storage .Azure
182
- if azureStorage == nil || len (azureStorage .AccountName ) == 0 {
183
- return fmt .Errorf ("storage account not yet provisioned" )
184
- }
185
- if azureStorage == nil || len (azureStorage .Container ) == 0 {
186
- return fmt .Errorf ("storage container not yet provisioned" )
187
- }
188
-
189
138
// the move-blobs cmd does not work on Azure Stack Hub. Users on ASH
190
139
// will have to copy the blobs on their own using something like az copy.
191
- if strings .EqualFold (azureStorage .CloudName , "AZURESTACKCLOUD" ) {
140
+ azureStorage := imageRegistryConfig .Status .Storage .Azure
141
+ if azureStorage != nil && strings .EqualFold (azureStorage .CloudName , "AZURESTACKCLOUD" ) {
192
142
return nil
193
143
}
194
144
195
- gen := resource .NewGeneratorAzurePathFixJob (
196
- c .jobLister ,
197
- c .batchClient ,
198
- c .secretLister ,
199
- c .infrastructureLister ,
200
- c .proxyLister ,
201
- c .openshiftConfigLister ,
202
- imageRegistryConfig ,
203
- c .kubeconfig ,
204
- )
205
-
206
145
// this controller was created to aid users migrating from 4.13.z to >=4.14.z.
207
146
// once users have migrated to an OCP version and have run this job at least once,
208
147
// this job is no longer needed. on OCP versions >=4.17 we can be certain that
@@ -227,15 +166,15 @@ func (c *AzurePathFixController) sync() error {
227
166
}
228
167
if len (removeConditionFns ) > 0 {
229
168
if _ , _ , err := v1helpers .UpdateStatus (
230
- context . TODO () ,
169
+ ctx ,
231
170
c .operatorClient ,
232
171
removeConditionFns ... ,
233
172
); err != nil {
234
173
return err
235
174
}
236
175
}
237
176
238
- _ , err = gen . Get ()
177
+ _ , err = c . jobLister . Get (defaults . AzurePathFixJobName )
239
178
if errors .IsNotFound (err ) {
240
179
return nil
241
180
} else if err != nil {
@@ -247,11 +186,13 @@ func (c *AzurePathFixController) sync() error {
247
186
GracePeriodSeconds : & gracePeriod ,
248
187
PropagationPolicy : & propagationPolicy ,
249
188
}
250
- if err := gen .Delete (opts ); err != nil {
189
+ if err := c .batchClient .Jobs (defaults .ImageRegistryOperatorNamespace ).Delete (
190
+ ctx , defaults .AzurePathFixJobName , opts ,
191
+ ); err != nil {
251
192
return err
252
193
}
253
194
}
254
- return err
195
+ return nil
255
196
}
256
197
257
198
func (c * AzurePathFixController ) Run (stopCh <- chan struct {}) {
0 commit comments