Skip to content

Commit

Permalink
Drop cvo as a library in favour of library-go to satisfy kube 1.18 deps
Browse files Browse the repository at this point in the history
  • Loading branch information
enxebre committed Mar 24, 2020
1 parent e7b4c23 commit 69986ee
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
24 changes: 12 additions & 12 deletions pkg/operator/status.go
@@ -1,16 +1,16 @@
package operator

import (
"context"
"fmt"
"reflect"
"strings"

"k8s.io/apimachinery/pkg/api/equality"

"github.com/golang/glog"
osconfigv1 "github.com/openshift/api/config/v1"
cvoresourcemerge "github.com/openshift/cluster-version-operator/lib/resourcemerge"
"github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -147,10 +147,10 @@ func newClusterOperatorStatusCondition(conditionType osconfigv1.ClusterStatusCon
//syncStatus applies the new condition to the mao ClusterOperator object.
func (optr *Operator) syncStatus(co *osconfigv1.ClusterOperator, conds []osconfigv1.ClusterOperatorStatusCondition) error {
for _, c := range conds {
cvoresourcemerge.SetOperatorStatusCondition(&co.Status.Conditions, c)
v1helpers.SetStatusCondition(&co.Status.Conditions, c)
}

_, err := optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(co)
_, err := optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(context.Background(), co, metav1.UpdateOptions{})
return err
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func (optr *Operator) updateRelatedObjects(co *osconfigv1.ClusterOperator) (*osc

if !equality.Semantic.DeepEqual(co.Status.RelatedObjects, relatedObjects) {
co.Status.RelatedObjects = relatedObjects
return optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(co)
return optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(context.Background(), co, metav1.UpdateOptions{})
}

return co, nil
Expand All @@ -257,14 +257,14 @@ func (optr *Operator) setMissingStatusConditions(co *osconfigv1.ClusterOperator)
var modified bool

for _, c := range optr.defaultStatusConditions() {
if cvoresourcemerge.FindOperatorStatusCondition(co.Status.Conditions, c.Type) == nil {
cvoresourcemerge.SetOperatorStatusCondition(&co.Status.Conditions, c)
if v1helpers.FindStatusCondition(co.Status.Conditions, c.Type) == nil {
v1helpers.SetStatusCondition(&co.Status.Conditions, c)
modified = true
}
}

if modified {
return optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(co)
return optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(context.Background(), co, metav1.UpdateOptions{})
}

return co, nil
Expand All @@ -273,21 +273,21 @@ func (optr *Operator) setMissingStatusConditions(co *osconfigv1.ClusterOperator)
// getClusterOperator returns the current ClusterOperator.
func (optr *Operator) getClusterOperator() (*osconfigv1.ClusterOperator, error) {
return optr.osClient.ConfigV1().ClusterOperators().
Get(clusterOperatorName, metav1.GetOptions{})
Get(context.Background(), clusterOperatorName, metav1.GetOptions{})
}

// createClusterOperator creates the ClusterOperator and updates its status.
func (optr *Operator) createClusterOperator() (*osconfigv1.ClusterOperator, error) {
defaultCO := optr.defaultClusterOperator()

co, err := optr.osClient.ConfigV1().ClusterOperators().Create(defaultCO)
co, err := optr.osClient.ConfigV1().ClusterOperators().Create(context.Background(), defaultCO, metav1.CreateOptions{})
if err != nil {
return nil, err
}

co.Status = defaultCO.Status

return optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(co)
return optr.osClient.ConfigV1().ClusterOperators().UpdateStatus(context.Background(), co, metav1.UpdateOptions{})
}

// getOrCreateClusterOperator fetches the current ClusterOperator or creates a
Expand Down
13 changes: 7 additions & 6 deletions pkg/operator/status_test.go
@@ -1,12 +1,13 @@
package operator

import (
"context"
"testing"
"time"

osconfigv1 "github.com/openshift/api/config/v1"
fakeconfigclientset "github.com/openshift/client-go/config/clientset/versioned/fake"
cvoresourcemerge "github.com/openshift/cluster-version-operator/lib/resourcemerge"
"github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -108,18 +109,18 @@ func TestOperatorStatusProgressing(t *testing.T) {
}

for _, expectedCondition := range tc.expectedConditions {
ok := cvoresourcemerge.IsOperatorStatusConditionPresentAndEqual(
ok := v1helpers.IsStatusConditionPresentAndEqual(
gotCO.Status.Conditions, expectedCondition.Type, expectedCondition.Status,
)
if !ok {
t.Errorf("wrong status for condition. Expected: %v, got: %v",
expectedCondition,
cvoresourcemerge.FindOperatorStatusCondition(gotCO.Status.Conditions, expectedCondition.Type))
v1helpers.FindStatusCondition(gotCO.Status.Conditions, expectedCondition.Type))
}
}

optr.statusProgressing()
gotCO, _ = optr.osClient.ConfigV1().ClusterOperators().Get(clusterOperatorName, metav1.GetOptions{})
gotCO, _ = optr.osClient.ConfigV1().ClusterOperators().Get(context.Background(), clusterOperatorName, metav1.GetOptions{})
var conditionAfterAnotherSync osconfigv1.ClusterOperatorStatusCondition
for _, coCondition := range gotCO.Status.Conditions {
if coCondition.Type == osconfigv1.OperatorProgressing {
Expand All @@ -130,13 +131,13 @@ func TestOperatorStatusProgressing(t *testing.T) {
assert.True(t, condition.LastTransitionTime.Equal(&conditionAfterAnotherSync.LastTransitionTime), "test-case %v expected LastTransitionTime not to be updated if condition state is same", i)

for _, expectedCondition := range tc.expectedConditions {
ok := cvoresourcemerge.IsOperatorStatusConditionPresentAndEqual(
ok := v1helpers.IsStatusConditionPresentAndEqual(
gotCO.Status.Conditions, expectedCondition.Type, expectedCondition.Status,
)
if !ok {
t.Errorf("wrong status for condition. Expected: %v, got: %v",
expectedCondition,
cvoresourcemerge.FindOperatorStatusCondition(gotCO.Status.Conditions, expectedCondition.Type))
v1helpers.FindStatusCondition(gotCO.Status.Conditions, expectedCondition.Type))
}
}
}
Expand Down
36 changes: 30 additions & 6 deletions pkg/operator/sync.go
Expand Up @@ -5,15 +5,15 @@ import (
"time"

"github.com/golang/glog"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/resource/resourceapply"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/utils/pointer"

"github.com/openshift/cluster-version-operator/lib/resourceapply"
)

const (
Expand Down Expand Up @@ -62,13 +62,25 @@ func (optr *Operator) syncAll(config *OperatorConfig) error {
}

func (optr *Operator) syncClusterAPIController(config *OperatorConfig) error {
controller := newDeployment(config, nil)
_, updated, err := resourceapply.ApplyDeployment(optr.kubeClient.AppsV1(), controller)
controllersDeployment := newDeployment(config, nil)
d, err := optr.deployLister.Deployments(controllersDeployment.GetNamespace()).Get(controllersDeployment.GetName())
generation := int64(-1)
if err != nil {
if !apierrors.IsNotFound(err) {
return err
}
}
if d != nil {
generation = d.Status.ObservedGeneration
}

_, updated, err := resourceapply.ApplyDeployment(optr.kubeClient.AppsV1(),
events.NewLoggingEventRecorder(optr.name), controllersDeployment, generation, false)
if err != nil {
return err
}
if updated {
return optr.waitForDeploymentRollout(controller)
return optr.waitForDeploymentRollout(controllersDeployment)
}
return nil
}
Expand All @@ -87,7 +99,19 @@ func (optr *Operator) syncBaremetalControllers(config *OperatorConfig) error {
}

metal3Deployment := newMetal3Deployment(config, baremetalProvisioningConfig)
_, updated, err := resourceapply.ApplyDeployment(optr.kubeClient.AppsV1(), metal3Deployment)
generation := int64(-1)
d, err := optr.deployLister.Deployments(metal3Deployment.GetNamespace()).Get(metal3Deployment.GetName())
if err != nil {
if !apierrors.IsNotFound(err) {
return err
}
}
if d != nil {
generation = d.Status.ObservedGeneration
}

_, updated, err := resourceapply.ApplyDeployment(optr.kubeClient.AppsV1(),
events.NewLoggingEventRecorder(optr.name), metal3Deployment, generation, false)
if err != nil {
return err
}
Expand Down

0 comments on commit 69986ee

Please sign in to comment.