Skip to content

Commit e27f30b

Browse files
committed
clean up AzurePathFix controller, removing unecessary informers
* drops use of the azurepathfixjob resource generator, as we only need to get and delete the job and we mostly benefit from the generator pattern when creating objects. * remove uneccessary informers. those were needed when creating the job object, but are no longer relevant for only getting and deleting it.
1 parent 97a3d21 commit e27f30b

File tree

4 files changed

+14
-69
lines changed

4 files changed

+14
-69
lines changed

pkg/defaults/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ const (
124124

125125
// InfrastructureResourceName is the name of the infrastructure config resource
126126
InfrastructureResourceName = "cluster"
127+
128+
// AzurePathFixJobName is the job name for the azure-path-fix job
129+
AzurePathFixJobName = "azure-path-fix"
127130
)
128131

129132
var (

pkg/operator/azurepathfixcontroller.go

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import (
1212
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1313
"k8s.io/apimachinery/pkg/util/wait"
1414
batchv1informers "k8s.io/client-go/informers/batch/v1"
15-
corev1informers "k8s.io/client-go/informers/core/v1"
1615
batchv1client "k8s.io/client-go/kubernetes/typed/batch/v1"
1716
batchv1listers "k8s.io/client-go/listers/batch/v1"
18-
corev1listers "k8s.io/client-go/listers/core/v1"
19-
restclient "k8s.io/client-go/rest"
2017
"k8s.io/client-go/tools/cache"
2118
"k8s.io/client-go/util/workqueue"
2219
"k8s.io/klog/v2"
@@ -26,11 +23,9 @@ import (
2623
configlisters "github.com/openshift/client-go/config/listers/config/v1"
2724
imageregistryv1informers "github.com/openshift/client-go/imageregistry/informers/externalversions/imageregistry/v1"
2825
imageregistryv1listers "github.com/openshift/client-go/imageregistry/listers/imageregistry/v1"
29-
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
3026
"github.com/openshift/library-go/pkg/operator/v1helpers"
3127

3228
"github.com/openshift/cluster-image-registry-operator/pkg/defaults"
33-
"github.com/openshift/cluster-image-registry-operator/pkg/resource"
3429
"github.com/openshift/cluster-image-registry-operator/pkg/storage/util"
3530
)
3631

@@ -39,45 +34,26 @@ type AzurePathFixController struct {
3934
operatorClient v1helpers.OperatorClient
4035
jobLister batchv1listers.JobNamespaceLister
4136
imageRegistryConfigLister imageregistryv1listers.ConfigLister
42-
secretLister corev1listers.SecretNamespaceLister
43-
podLister corev1listers.PodNamespaceLister
4437
infrastructureLister configlisters.InfrastructureLister
45-
proxyLister configlisters.ProxyLister
46-
openshiftConfigLister corev1listers.ConfigMapNamespaceLister
47-
kubeconfig *restclient.Config
4838

4939
cachesToSync []cache.InformerSynced
5040
queue workqueue.RateLimitingInterface
51-
52-
featureGateAccessor featuregates.FeatureGateAccess
5341
}
5442

5543
func NewAzurePathFixController(
56-
kubeconfig *restclient.Config,
5744
batchClient batchv1client.BatchV1Interface,
5845
operatorClient v1helpers.OperatorClient,
5946
jobInformer batchv1informers.JobInformer,
6047
imageRegistryConfigInformer imageregistryv1informers.ConfigInformer,
6148
infrastructureInformer configv1informers.InfrastructureInformer,
62-
secretInformer corev1informers.SecretInformer,
63-
proxyInformer configv1informers.ProxyInformer,
64-
openshiftConfigInformer corev1informers.ConfigMapInformer,
65-
podInformer corev1informers.PodInformer,
66-
featureGateAccessor featuregates.FeatureGateAccess,
6749
) (*AzurePathFixController, error) {
6850
c := &AzurePathFixController{
6951
batchClient: batchClient,
7052
operatorClient: operatorClient,
7153
jobLister: jobInformer.Lister().Jobs(defaults.ImageRegistryOperatorNamespace),
7254
imageRegistryConfigLister: imageRegistryConfigInformer.Lister(),
7355
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,
7956
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "AzurePathFixController"),
80-
featureGateAccessor: featureGateAccessor,
8157
}
8258

8359
if _, err := jobInformer.Informer().AddEventHandler(c.eventHandler()); err != nil {
@@ -90,31 +66,10 @@ func NewAzurePathFixController(
9066
}
9167
c.cachesToSync = append(c.cachesToSync, imageRegistryConfigInformer.Informer().HasSynced)
9268

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.
9671
c.cachesToSync = append(c.cachesToSync, infrastructureInformer.Informer().HasSynced)
9772

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-
11873
// bootstrap the job if it doesn't exist
11974
c.queue.Add("instance")
12075

@@ -163,6 +118,8 @@ func (c *AzurePathFixController) processNextWorkItem() bool {
163118
}
164119

165120
func (c *AzurePathFixController) sync() error {
121+
ctx := context.TODO()
122+
166123
// this controller was made to run specifically on Azure,
167124
// so if we detect a different cloud, skip it.
168125
infra, err := util.GetInfrastructure(c.infrastructureLister)
@@ -185,17 +142,6 @@ func (c *AzurePathFixController) sync() error {
185142
return nil
186143
}
187144

188-
gen := resource.NewGeneratorAzurePathFixJob(
189-
c.jobLister,
190-
c.batchClient,
191-
c.secretLister,
192-
c.infrastructureLister,
193-
c.proxyLister,
194-
c.openshiftConfigLister,
195-
imageRegistryConfig,
196-
c.kubeconfig,
197-
)
198-
199145
// this controller was created to aid users migrating from 4.13.z to >=4.14.z.
200146
// once users have migrated to an OCP version and have run this job at least once,
201147
// this job is no longer needed. on OCP versions >=4.17 we can be certain that
@@ -220,15 +166,15 @@ func (c *AzurePathFixController) sync() error {
220166
}
221167
if len(removeConditionFns) > 0 {
222168
if _, _, err := v1helpers.UpdateStatus(
223-
context.TODO(),
169+
ctx,
224170
c.operatorClient,
225171
removeConditionFns...,
226172
); err != nil {
227173
return err
228174
}
229175
}
230176

231-
_, err = gen.Get()
177+
_, err = c.jobLister.Get(defaults.AzurePathFixJobName)
232178
if errors.IsNotFound(err) {
233179
return nil
234180
} else if err != nil {
@@ -240,11 +186,13 @@ func (c *AzurePathFixController) sync() error {
240186
GracePeriodSeconds: &gracePeriod,
241187
PropagationPolicy: &propagationPolicy,
242188
}
243-
if err := gen.Delete(opts); err != nil {
189+
if err := c.batchClient.Jobs(defaults.ImageRegistryOperatorNamespace).Delete(
190+
ctx, defaults.AzurePathFixJobName, opts,
191+
); err != nil {
244192
return err
245193
}
246194
}
247-
return err
195+
return nil
248196
}
249197

250198
func (c *AzurePathFixController) Run(stopCh <-chan struct{}) {

pkg/operator/starter.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,17 +201,11 @@ func RunOperator(ctx context.Context, kubeconfig *restclient.Config) error {
201201
}
202202

203203
azurePathFixController, err := NewAzurePathFixController(
204-
kubeconfig,
205204
kubeClient.BatchV1(),
206205
configOperatorClient,
207206
kubeInformers.Batch().V1().Jobs(),
208207
imageregistryInformers.Imageregistry().V1().Configs(),
209208
configInformers.Config().V1().Infrastructures(),
210-
kubeInformers.Core().V1().Secrets(),
211-
configInformers.Config().V1().Proxies(),
212-
kubeInformersForOpenShiftConfig.Core().V1().ConfigMaps(),
213-
kubeInformers.Core().V1().Pods(),
214-
featureGateAccessor,
215209
)
216210
if err != nil {
217211
return err

pkg/resource/azurepathfixjob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (gapfj *generatorAzurePathFixJob) GetNamespace() string {
7070
}
7171

7272
func (gapfj *generatorAzurePathFixJob) GetName() string {
73-
return "azure-path-fix"
73+
return defaults.AzurePathFixJobName
7474
}
7575

7676
func (gapfj *generatorAzurePathFixJob) expected() (runtime.Object, error) {

0 commit comments

Comments
 (0)