Skip to content
Merged
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
26 changes: 15 additions & 11 deletions pkg/operator2/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
configclient "github.com/openshift/client-go/config/clientset/versioned"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
configinformer "github.com/openshift/client-go/config/informers/externalversions"
authopclient "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1"
authopinformer "github.com/openshift/client-go/operator/informers/externalversions/operator/v1"
routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
routeinformer "github.com/openshift/client-go/route/informers/externalversions/route/v1"
"github.com/openshift/cluster-authentication-operator/pkg/boilerplate/controller"
Expand All @@ -28,8 +26,9 @@ import (
)

const (
targetName = "openshift-authentication"
globalConfigName = "cluster"
targetName = "openshift-authentication"
targetNameOperator = "openshift-authentication-operator"
globalConfigName = "cluster"

machineConfigNamespace = "openshift-config-managed"
userConfigNamespace = "openshift-config"
Expand Down Expand Up @@ -75,7 +74,7 @@ const (
)

type authOperator struct {
authOperatorConfig authopclient.AuthenticationInterface
authOperatorConfigClient OperatorClient

recorder events.Recorder

Expand All @@ -94,8 +93,7 @@ type authOperator struct {
}

func NewAuthenticationOperator(
authOpConfigInformer authopinformer.AuthenticationInformer,
authOpConfigClient authopclient.AuthenticationsGetter,
authOpConfigClient OperatorClient,
kubeInformersNamespaced informers.SharedInformerFactory,
kubeClient kubernetes.Interface,
routeInformer routeinformer.RouteInformer,
Expand All @@ -106,7 +104,7 @@ func NewAuthenticationOperator(
resourceSyncer resourcesynccontroller.ResourceSyncer,
) operator.Runner {
c := &authOperator{
authOperatorConfig: authOpConfigClient.Authentications(),
authOperatorConfigClient: authOpConfigClient,

recorder: recorder,

Expand Down Expand Up @@ -139,15 +137,15 @@ func NewAuthenticationOperator(
operator.WithInformer(coreInformers.Secrets(), prefixFilter),
operator.WithInformer(coreInformers.ConfigMaps(), prefixFilter),

operator.WithInformer(authOpConfigInformer, configNameFilter),
operator.WithInformer(authOpConfigClient.Informers.Operator().V1().Authentications(), configNameFilter),
operator.WithInformer(configV1Informers.Authentications(), configNameFilter),
operator.WithInformer(configV1Informers.OAuths(), configNameFilter),
operator.WithInformer(configV1Informers.Consoles(), configNameFilter, controller.WithNoSync()),
)
}

func (c *authOperator) Key() (metav1.Object, error) {
return c.authOperatorConfig.Get(globalConfigName, metav1.GetOptions{})
return c.authOperatorConfigClient.Client.Authentications().Get(globalConfigName, metav1.GetOptions{})
}

func (c *authOperator) Sync(obj metav1.Object) error {
Expand All @@ -158,10 +156,16 @@ func (c *authOperator) Sync(obj metav1.Object) error {
}

if err := c.handleSync(operatorConfig); err != nil {
if statusErr := c.setFailingStatus(operatorConfig, "OperatorSyncLoopError", err.Error()); statusErr != nil {
glog.Errorf("error updating operator status: %s", statusErr)
}

return err
}

// TODO update states and handle ClusterOperator spec/status
if statusErr := c.setAvailableStatus(operatorConfig); statusErr != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wholly insufficient - ex: if the deployment fails to rollout we would be stating everything is fine.

glog.Errorf("error updating operator status: %s", statusErr)
}

return nil
}
Expand Down
62 changes: 62 additions & 0 deletions pkg/operator2/operatorclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package operator2

import (
"k8s.io/client-go/tools/cache"

operatorv1 "github.com/openshift/api/operator/v1"

operatorconfigclient "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1"
operatorclientinformers "github.com/openshift/client-go/operator/informers/externalversions"
)

type OperatorClient struct {
Informers operatorclientinformers.SharedInformerFactory
Client operatorconfigclient.AuthenticationsGetter
}

func (c OperatorClient) Informer() cache.SharedIndexInformer {
return c.Informers.Operator().V1().Authentications().Informer()
}

func (c OperatorClient) GetOperatorState() (*operatorv1.OperatorSpec, *operatorv1.OperatorStatus, string, error) {
instance, err := c.Informers.Operator().V1().Authentications().Lister().Get(globalConfigName)
if err != nil {
return nil, nil, "", err
}

return &instance.Spec.OperatorSpec, &instance.Status.OperatorStatus, instance.ResourceVersion, nil
}

func (c OperatorClient) UpdateOperatorSpec(resourceVersion string, spec *operatorv1.OperatorSpec) (*operatorv1.OperatorSpec, string, error) {
original, err := c.Informers.Operator().V1().Authentications().Lister().Get(globalConfigName)
if err != nil {
return nil, "", err
}
copy := original.DeepCopy()
copy.ResourceVersion = resourceVersion
copy.Spec.OperatorSpec = *spec

ret, err := c.Client.Authentications().Update(copy)
if err != nil {
return nil, "", err
}

return &ret.Spec.OperatorSpec, ret.ResourceVersion, nil
}

func (c OperatorClient) UpdateOperatorStatus(resourceVersion string, status *operatorv1.OperatorStatus) (*operatorv1.OperatorStatus, error) {
original, err := c.Informers.Operator().V1().Authentications().Lister().Get(globalConfigName)
if err != nil {
return nil, err
}
copy := original.DeepCopy()
copy.ResourceVersion = resourceVersion
copy.Status.OperatorStatus = *status

ret, err := c.Client.Authentications().Update(copy)
if err != nil {
return nil, err
}

return &ret.Status.OperatorStatus, nil
}
55 changes: 26 additions & 29 deletions pkg/operator2/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"

configv1 "github.com/openshift/api/config/v1"
operatorv1 "github.com/openshift/api/operator/v1"
Expand All @@ -22,6 +21,7 @@ import (
routeinformer "github.com/openshift/client-go/route/informers/externalversions"
"github.com/openshift/library-go/pkg/controller/controllercmd"
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
"github.com/openshift/library-go/pkg/operator/status"
"github.com/openshift/library-go/pkg/operator/v1helpers"
)

Expand Down Expand Up @@ -114,17 +114,21 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {

resourceSyncerInformers := v1helpers.NewKubeInformersForNamespaces(kubeClient, targetName, userConfigNamespace)

operatorClient := &OperatorClient{
authOperatorConfigInformers,
authConfigClient.OperatorV1(),
}

resourceSyncer := resourcesynccontroller.NewResourceSyncController(
operatorClient{}, // TODO fix
operatorClient,
resourceSyncerInformers,
v1helpers.CachedSecretGetter(kubeClient.CoreV1(), resourceSyncerInformers),
v1helpers.CachedConfigMapGetter(kubeClient.CoreV1(), resourceSyncerInformers),
ctx.EventRecorder,
)

operator := NewAuthenticationOperator(
authOperatorConfigInformers.Operator().V1().Authentications(),
authConfigClient.OperatorV1(),
*operatorClient,
kubeInformersNamespaced,
kubeClient,
routeInformersNamespaced.Route().V1().Routes(),
Expand All @@ -135,6 +139,23 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {
resourceSyncer,
)

clusterOperatorStatus := status.NewClusterOperatorStatusController(
targetName,
[]configv1.ObjectReference{
{Group: operatorv1.GroupName, Resource: "authentications", Name: globalConfigName},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add the infrastructure top level config per #79

{Group: configv1.GroupName, Resource: "authentications", Name: globalConfigName},
{Group: configv1.GroupName, Resource: "oauths", Name: globalConfigName},
{Resource: "namespaces", Name: userConfigNamespace},
{Resource: "namespaces", Name: machineConfigNamespace},
{Resource: "namespaces", Name: targetName},
{Resource: "namespaces", Name: targetNameOperator},
},
configClient.ConfigV1(),
operatorClient,
status.NewVersionGetter(),
ctx.EventRecorder,
)

for _, informer := range []interface {
Start(stopCh <-chan struct{})
}{
Expand All @@ -149,6 +170,7 @@ func RunOperator(ctx *controllercmd.ControllerContext) error {

go operator.Run(ctx.Done())
go resourceSyncer.Run(1, ctx.Done())
go clusterOperatorStatus.Run(1, ctx.Done())

<-ctx.Done()

Expand All @@ -160,28 +182,3 @@ func singleNameListOptions(name string) func(opts *v1.ListOptions) {
opts.FieldSelector = fields.OneTermEqualSelector("metadata.name", name).String()
}
}

// temp hack since I do not care about this right now
type operatorClient struct{}

func (operatorClient) Informer() cache.SharedIndexInformer {
return fakeInformer{}
}

func (operatorClient) GetOperatorState() (spec *operatorv1.OperatorSpec, status *operatorv1.OperatorStatus, resourceVersion string, err error) {
return &operatorv1.OperatorSpec{}, &operatorv1.OperatorStatus{}, "", nil
}

func (operatorClient) UpdateOperatorSpec(string, *operatorv1.OperatorSpec) (spec *operatorv1.OperatorSpec, resourceVersion string, err error) {
return nil, "", nil
}

func (operatorClient) UpdateOperatorStatus(string, *operatorv1.OperatorStatus) (status *operatorv1.OperatorStatus, err error) {
return nil, nil
}

type fakeInformer struct {
cache.SharedIndexInformer // panics if anything other than AddEventHandler gets called
}

func (fakeInformer) AddEventHandler(_ cache.ResourceEventHandler) {}
58 changes: 58 additions & 0 deletions pkg/operator2/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package operator2

import (
operatorv1 "github.com/openshift/api/operator/v1"
"github.com/openshift/library-go/pkg/operator/v1helpers"
)

func (c *authOperator) setFailingStatus(operatorConfig *operatorv1.Authentication, reason, message string) error {
failStatusFunc := func(status *operatorv1.OperatorStatus) error {
v1helpers.SetOperatorCondition(&status.Conditions,
operatorv1.OperatorCondition{
Type: operatorv1.OperatorStatusTypeFailing,
Status: operatorv1.ConditionTrue,
Reason: reason,
Message: message,
})

v1helpers.SetOperatorCondition(&status.Conditions, operatorv1.OperatorCondition{
Type: operatorv1.OperatorStatusTypeProgressing,
Status: operatorv1.ConditionFalse,
})

v1helpers.SetOperatorCondition(&status.Conditions,
operatorv1.OperatorCondition{
Type: operatorv1.OperatorStatusTypeAvailable,
Status: operatorv1.ConditionFalse,
})

return nil
}

_, _, err := v1helpers.UpdateStatus(c.authOperatorConfigClient, failStatusFunc)
return err
}

func (c *authOperator) setAvailableStatus(operatorConfig *operatorv1.Authentication) error {
availStatusFunc := func(status *operatorv1.OperatorStatus) error {
v1helpers.SetOperatorCondition(&status.Conditions, operatorv1.OperatorCondition{
Type: operatorv1.OperatorStatusTypeAvailable,
Status: operatorv1.ConditionTrue,
})

v1helpers.SetOperatorCondition(&status.Conditions, operatorv1.OperatorCondition{
Type: operatorv1.OperatorStatusTypeProgressing,
Status: operatorv1.ConditionFalse,
})

v1helpers.SetOperatorCondition(&status.Conditions, operatorv1.OperatorCondition{
Type: operatorv1.OperatorStatusTypeFailing,
Status: operatorv1.ConditionFalse,
})

return nil
}

_, _, err := v1helpers.UpdateStatus(c.authOperatorConfigClient, availStatusFunc)
return err
}