Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API-1835: fix up minor comments from Lucasz #1802

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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