Skip to content

Commit

Permalink
fix up minor comments from Lucasz
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Sep 26, 2024
1 parent 2402ef3 commit 3284c43
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"context"
"time"

applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"

configv1 "github.com/openshift/api/config/v1"
operatorsv1 "github.com/openshift/api/operator/v1"
operatorv1 "github.com/openshift/api/operator/v1"
configinformers "github.com/openshift/client-go/config/informers/externalversions"
configv1listers "github.com/openshift/client-go/config/listers/config/v1"
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/apiserver/audit"
"github.com/openshift/library-go/pkg/operator/events"
Expand All @@ -35,7 +34,7 @@ type auditPolicyController struct {
// NewAuditPolicyController create a controller that watches the config.openshift.io/v1 APIServer object
// and reconciles a ConfigMap in the target namespace with the audit.k8s.io/v1 policy.yaml file.
func NewAuditPolicyController(
name string,
instanceName string,
targetNamespace string,
targetConfigMapName string,
apiserverConfigLister configv1listers.APIServerLister,
Expand All @@ -46,20 +45,23 @@ func NewAuditPolicyController(
eventRecorder events.Recorder,
) factory.Controller {
c := &auditPolicyController{
controllerInstanceName: factory.ControllerInstanceName(name, "AuditPolicy"),
controllerInstanceName: factory.ControllerInstanceName(instanceName, "AuditPolicy"),
operatorClient: operatorClient,
apiserverConfigLister: apiserverConfigLister,
kubeClient: kubeClient,
targetNamespace: targetNamespace,
targetConfigMapName: targetConfigMapName,
}

return factory.New().WithSync(c.sync).ResyncEvery(10*time.Second).WithInformers(
configInformers.Config().V1().APIServers().Informer(),
kubeInformersForTargetNamesace.Core().V1().ConfigMaps().Informer(),
operatorClient.Informer(),
).ToController(
"auditPolicyController", // don't change what is passed here unless you also remove the old FooDegraded condition
return factory.New().
WithSync(c.sync).
ResyncEvery(10*time.Second).
WithInformers(
configInformers.Config().V1().APIServers().Informer(),
kubeInformersForTargetNamesace.Core().V1().ConfigMaps().Informer(),
operatorClient.Informer(),
).ToController(
c.controllerInstanceName,
eventRecorder.WithComponentSuffix("audit-policy-controller"),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
)

type finalizerController struct {
name string
namespaceName string
controllerInstanceName string
namespaceName string

namespaceGetter v1.NamespacesGetter
podLister corev1listers.PodLister
Expand All @@ -41,20 +41,22 @@ func NewFinalizerController(
namespaceGetter v1.NamespacesGetter,
eventRecorder events.Recorder,
) factory.Controller {
fullname := "NamespaceFinalizerController_" + namespaceName
c := &finalizerController{
name: fullname,
namespaceName: namespaceName,
namespaceGetter: namespaceGetter,
podLister: kubeInformersForTargetNamespace.Core().V1().Pods().Lister(),
dsLister: kubeInformersForTargetNamespace.Apps().V1().DaemonSets().Lister(),
controllerInstanceName: factory.ControllerInstanceName(namespaceName, "NamespaceFinalizerController"),
namespaceName: namespaceName,
namespaceGetter: namespaceGetter,
podLister: kubeInformersForTargetNamespace.Core().V1().Pods().Lister(),
dsLister: kubeInformersForTargetNamespace.Apps().V1().DaemonSets().Lister(),
}

return factory.New().ResyncEvery(time.Minute).WithSync(c.sync).WithInformers(
kubeInformersForTargetNamespace.Core().V1().Pods().Informer(),
kubeInformersForTargetNamespace.Apps().V1().DaemonSets().Informer(),
).ToController(
fullname, // don't change what is passed here unless you also remove the old FooDegraded condition
return factory.New().
ResyncEvery(time.Minute).
WithSync(c.sync).
WithInformers(
kubeInformersForTargetNamespace.Core().V1().Pods().Informer(),
kubeInformersForTargetNamespace.Apps().V1().DaemonSets().Informer(),
).ToController(
c.controllerInstanceName,
eventRecorder.WithComponentSuffix("finalizer-controller"),
)
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/operator/apiserver/controller/workload/workload.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Delegate interface {
// Callers must provide a sync function for delegation. It should bring the desired workload into operation.
// The returned state along with errors will be converted into conditions and persisted in the status field.
type Controller struct {
controllerInstanceName string

// conditionsPrefix an optional prefix that will be used as operator's condition type field for example APIServerDeploymentDegraded where APIServer indicates the prefix
conditionsPrefix string
operatorNamespace string
Expand Down Expand Up @@ -77,7 +79,7 @@ type Controller struct {
// the "operatorNamespace" is used to set "version-mapping" in the correct namespace
//
// the "targetNamespace" represent the namespace for the managed resource (DaemonSet)
func NewController(name, operatorNamespace, targetNamespace, targetOperandVersion, operandNamePrefix, conditionsPrefix string,
func NewController(instanceName, operatorNamespace, targetNamespace, targetOperandVersion, operandNamePrefix, conditionsPrefix string,
operatorClient v1helpers.OperatorClient,
kubeClient kubernetes.Interface,
podLister corev1listers.PodLister,
Expand All @@ -89,6 +91,7 @@ func NewController(name, operatorNamespace, targetNamespace, targetOperandVersio
versionRecorder status.VersionGetter,
) factory.Controller {
controllerRef := &Controller{
controllerInstanceName: factory.ControllerInstanceName(instanceName, "Workload"),
operatorNamespace: operatorNamespace,
targetNamespace: targetNamespace,
targetOperandVersion: targetOperandVersion,
Expand All @@ -100,7 +103,7 @@ func NewController(name, operatorNamespace, targetNamespace, targetOperandVersio
delegate: delegate,
openshiftClusterConfigClient: openshiftClusterConfigClient,
versionRecorder: versionRecorder,
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), name),
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), instanceName),
}

c := factory.New()
Expand All @@ -111,7 +114,7 @@ func NewController(name, operatorNamespace, targetNamespace, targetOperandVersio
return c.WithSync(controllerRef.sync).
WithInformers(informers...).
ToController(
fmt.Sprintf("%sWorkloadController", name), // don't change what is passed here unless you also remove the old FooDegraded condition
controllerRef.controllerInstanceName,
eventRecorder,
)
}
Expand Down

0 comments on commit 3284c43

Please sign in to comment.