Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Commit

Permalink
Merge pull request #65 from stlaz/serviceca_hack
Browse files Browse the repository at this point in the history
operator: don't do anything if service-ca-operator is running
  • Loading branch information
openshift-merge-robot authored Feb 22, 2019
2 parents 84f0c33 + c658ab6 commit 3092421
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
29 changes: 27 additions & 2 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
apiequality "k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
appsclientv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
coreclientv1 "k8s.io/client-go/kubernetes/typed/core/v1"
Expand All @@ -29,7 +31,8 @@ import (
const targetNamespaceName = "openshift-service-cert-signer"

type serviceCertSignerOperator struct {
operatorConfigClient scsclientv1alpha1.ServiceCertSignerOperatorConfigsGetter
operatorConfigClient scsclientv1alpha1.ServiceCertSignerOperatorConfigsGetter
serviceCAOperatorConfigClient dynamic.ResourceInterface

appsv1Client appsclientv1.AppsV1Interface
corev1Client coreclientv1.CoreV1Interface
Expand All @@ -40,12 +43,14 @@ func NewServiceCertSignerOperator(
serviceCertSignerConfigInformer scsinformerv1alpha1.ServiceCertSignerOperatorConfigInformer,
namespacedKubeInformers informers.SharedInformerFactory,
operatorConfigClient scsclientv1alpha1.ServiceCertSignerOperatorConfigsGetter,
serviceCAOperatorConfigClient dynamic.ResourceInterface,
appsv1Client appsclientv1.AppsV1Interface,
corev1Client coreclientv1.CoreV1Interface,
rbacv1Client rbacclientv1.RbacV1Interface,
) operator.Runner {
c := &serviceCertSignerOperator{
operatorConfigClient: operatorConfigClient,
operatorConfigClient: operatorConfigClient,
serviceCAOperatorConfigClient: serviceCAOperatorConfigClient,

appsv1Client: appsv1Client,
corev1Client: corev1Client,
Expand Down Expand Up @@ -115,6 +120,11 @@ func (c serviceCertSignerOperator) Sync(obj metav1.Object) error {
return nil
}

// don't do anything if ServiceCA operator is running, it's the superior operator
if isServiceCARunning(c.serviceCAOperatorConfigClient) {
return nil
}

operatorConfigOriginal := operatorConfig.DeepCopy()

var currentActualVerion *semver.Version
Expand Down Expand Up @@ -194,3 +204,18 @@ func (c serviceCertSignerOperator) Sync(obj metav1.Object) error {

return utilerrors.NewAggregate(errors)
}

func isServiceCARunning(serviceCAConfigClient dynamic.ResourceInterface) bool {
serviceCAConfig, err := serviceCAConfigClient.Get("cluster", metav1.GetOptions{})
if err != nil {
return false
}

// discard errors parsing the obtained status
servicaCAStatus, found, err := unstructured.NestedString(serviceCAConfig.Object, "spec", "managementState")
if err == nil && found && servicaCAStatus == string(operatorsv1alpha1.Managed) {
return true
}

return false
}
9 changes: 9 additions & 0 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
Expand All @@ -16,6 +17,12 @@ import (
"github.com/openshift/library-go/pkg/operator/status"
)

var serviceCAResource = schema.GroupVersionResource{
Group: "operator.openshift.io",
Version: "v1",
Resource: "servicecas",
}

func RunOperator(clientConfig *rest.Config, stopCh <-chan struct{}) error {
kubeClient, err := kubernetes.NewForConfig(clientConfig)
if err != nil {
Expand All @@ -29,6 +36,7 @@ func RunOperator(clientConfig *rest.Config, stopCh <-chan struct{}) error {
if err != nil {
return err
}
serviceCAConfigClient := dynamicClient.Resource(serviceCAResource)

operatorInformers := scsinformers.NewSharedInformerFactory(scsClient, 10*time.Minute)
kubeInformersNamespaced := informers.NewFilteredSharedInformerFactory(kubeClient, 10*time.Minute, targetNamespaceName, nil)
Expand All @@ -44,6 +52,7 @@ func RunOperator(clientConfig *rest.Config, stopCh <-chan struct{}) error {
operatorInformers.Servicecertsigner().V1alpha1().ServiceCertSignerOperatorConfigs(),
kubeInformersNamespaced,
scsClient.ServicecertsignerV1alpha1(),
serviceCAConfigClient,
kubeClient.AppsV1(),
kubeClient.CoreV1(),
kubeClient.RbacV1(),
Expand Down

0 comments on commit 3092421

Please sign in to comment.