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

Update go.mod with no replace directives & k8s ver #449

Merged
merged 1 commit into from
Apr 13, 2022
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
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
sudo go version
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: get go version
run: go version
- name: Gofmt and License checks
run: make check
- name: unit tests
Expand All @@ -37,7 +39,7 @@ jobs:
uses: codecov/[email protected]
- name: Set env
run: |
echo "KUBERNETES_VERSION=v1.20.13" >> $GITHUB_ENV
echo "KUBERNETES_VERSION=v1.23.1" >> $GITHUB_ENV
echo "OPERATOR_SDK_VERSION=v0.19.4" >> $GITHUB_ENV
echo "MINIKUBE_VERSION=v1.24.0" >> $GITHUB_ENV
echo "KUBERNETES_CONFIG_FILE=$HOME/.kube/config" >> $GITHUB_ENV
Expand Down
983 changes: 802 additions & 181 deletions config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions controllers/zookeepercluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ package controllers
import (
"context"
"fmt"
"strconv"
"time"

"github.com/pravega/zookeeper-operator/pkg/controller/config"
"github.com/pravega/zookeeper-operator/pkg/utils"
"github.com/pravega/zookeeper-operator/pkg/yamlexporter"
"github.com/pravega/zookeeper-operator/pkg/zk"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"strconv"
"time"

"github.com/go-logr/logr"
zookeeperv1beta1 "github.com/pravega/zookeeper-operator/api/v1beta1"
Expand Down Expand Up @@ -59,7 +60,7 @@ type reconcileFun func(cluster *zookeeperv1beta1.ZookeeperCluster) error
// +kubebuilder:rbac:groups=zookeeper.pravega.io.zookeeper.pravega.io,resources=zookeeperclusters,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=zookeeper.pravega.io.zookeeper.pravega.io,resources=zookeeperclusters/status,verbs=get;update;patch

func (r *ZookeeperClusterReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) {
func (r *ZookeeperClusterReconciler) Reconcile(_ context.Context, request ctrl.Request) (ctrl.Result, error) {
r.Log = log.WithValues(
"Request.Namespace", request.Namespace,
"Request.Name", request.Name)
Expand Down Expand Up @@ -262,7 +263,7 @@ func (r *ZookeeperClusterReconciler) updateStatefulSet(instance *zookeeperv1beta

func (r *ZookeeperClusterReconciler) upgradeStatefulSet(instance *zookeeperv1beta1.ZookeeperCluster, foundSts *appsv1.StatefulSet) (err error) {

//Getting the upgradeCondition from the zk clustercondition
// Getting the upgradeCondition from the zk clustercondition
_, upgradeCondition := instance.Status.GetClusterCondition(zookeeperv1beta1.ClusterConditionUpgrading)

if upgradeCondition == nil {
Expand All @@ -271,8 +272,8 @@ func (r *ZookeeperClusterReconciler) upgradeStatefulSet(instance *zookeeperv1bet
return nil
}

//Setting the upgrade condition to true to trigger the upgrade
//When the zk cluster is upgrading Statefulset CurrentRevision and UpdateRevision are not equal and zk cluster image tag is not equal to CurrentVersion
// Setting the upgrade condition to true to trigger the upgrade
// When the zk cluster is upgrading Statefulset CurrentRevision and UpdateRevision are not equal and zk cluster image tag is not equal to CurrentVersion
if upgradeCondition.Status == corev1.ConditionFalse {
if instance.Status.IsClusterInReadyState() && foundSts.Status.CurrentRevision != foundSts.Status.UpdateRevision && instance.Spec.Image.Tag != instance.Status.CurrentVersion {
instance.Status.TargetVersion = instance.Spec.Image.Tag
Expand All @@ -281,20 +282,20 @@ func (r *ZookeeperClusterReconciler) upgradeStatefulSet(instance *zookeeperv1bet
}
}

//checking if the upgrade is in progress
// checking if the upgrade is in progress
if upgradeCondition.Status == corev1.ConditionTrue {
//checking when the targetversion is empty
// checking when the targetversion is empty
if instance.Status.TargetVersion == "" {
r.Log.Info("upgrading to an unknown version: cancelling upgrade process")
return r.clearUpgradeStatus(instance)
}
//Checking for upgrade completion
// Checking for upgrade completion
if foundSts.Status.CurrentRevision == foundSts.Status.UpdateRevision {
instance.Status.CurrentVersion = instance.Status.TargetVersion
r.Log.Info("upgrade completed")
return r.clearUpgradeStatus(instance)
}
//updating the upgradecondition if upgrade is in progress
// updating the upgradecondition if upgrade is in progress
if foundSts.Status.CurrentRevision != foundSts.Status.UpdateRevision {
r.Log.Info("upgrade in progress")
if fmt.Sprint(foundSts.Status.UpdatedReplicas) != upgradeCondition.Message {
Expand Down Expand Up @@ -555,7 +556,7 @@ func (r *ZookeeperClusterReconciler) reconcileClusterStatus(instance *zookeeperv
instance.Status.Members.Ready = readyMembers
instance.Status.Members.Unready = unreadyMembers

//If Cluster is in a ready state...
// If Cluster is in a ready state...
if instance.Spec.Replicas == instance.Status.ReadyReplicas && (!instance.Status.MetaRootCreated) {
r.Log.Info("Cluster is Ready, Creating ZK Metadata...")
zkUri := utils.GetZkServiceUri(instance)
Expand Down
90 changes: 44 additions & 46 deletions controllers/zookeepercluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
corev1 "k8s.io/api/core/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -106,9 +105,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
)

BeforeEach(func() {
cl = fake.NewFakeClient(z)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(z).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("shouldn't error", func() {
Expand All @@ -135,9 +134,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {

BeforeEach(func() {
z.WithDefaults()
cl = fake.NewFakeClient(z)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(z).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not error", func() {
Expand Down Expand Up @@ -206,9 +205,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next := z.DeepCopy()
st := zk.MakeStatefulSet(z)
next.Spec.Replicas = 6
cl = fake.NewFakeClient([]runtime.Object{next, st}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, st).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand All @@ -234,9 +233,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
z.Status.Init()
next := z.DeepCopy()
st := zk.MakeStatefulSet(z)
cl = fake.NewFakeClient([]runtime.Object{next, st}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, st).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand Down Expand Up @@ -265,9 +264,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
z.Status.Init()
next = z.DeepCopy()
sa = zk.MakeServiceAccount(z)
cl = fake.NewFakeClientWithScheme(s, []runtime.Object{next, sa}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, sa).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand All @@ -282,9 +281,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
})
It("should update the service account", func() {
next.Spec.Pod.ImagePullSecrets = []corev1.LocalObjectReference{{Name: "test-pull-secret"}}
cl = fake.NewFakeClientWithScheme(s, []runtime.Object{next, sa}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, sa).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
_, err := r.Reconcile(req)
_, err := r.Reconcile(context.TODO(), req)
Ω(err).To(BeNil())

foundSA := &corev1.ServiceAccount{}
Expand All @@ -307,15 +306,15 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next.Status.CurrentVersion = "0.2.6"
next.Status.SetPodsReadyConditionTrue()
st := zk.MakeStatefulSet(z)
cl = fake.NewFakeClient([]runtime.Object{next, st}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, st).Build()
st = &appsv1.StatefulSet{}
err = cl.Get(context.TODO(), req.NamespacedName, st)
//changing the Revision value to simulate the upgrade scenario
// changing the Revision value to simulate the upgrade scenario
st.Status.CurrentRevision = "CurrentRevision"
st.Status.UpdateRevision = "UpdateRevision"
cl.Status().Update(context.TODO(), st)
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand Down Expand Up @@ -347,7 +346,7 @@ var _ = Describe("ZookeeperCluster Controller", func() {
It("should check if the cluster is in upgrade failed state", func() {
z.Status.SetErrorConditionTrue("UpgradeFailed", " ")
cl.Status().Update(context.TODO(), z)
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
Ω(err).To(BeNil())
})
})
Expand All @@ -367,19 +366,19 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next.Status.TargetVersion = "0.2.7"
next.Status.SetUpgradingConditionTrue(" ", " ")
st := zk.MakeStatefulSet(z)
cl = fake.NewFakeClient([]runtime.Object{next, st}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, st).Build()
st = &appsv1.StatefulSet{}
err = cl.Get(context.TODO(), req.NamespacedName, st)
//changing the Revision value to simulate the upgrade scenario completion
// changing the Revision value to simulate the upgrade scenario completion
st.Status.CurrentRevision = "complete"
st.Status.UpdateRevision = "complete"
cl.Status().Update(context.TODO(), st)
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
foundZookeeper := &v1beta1.ZookeeperCluster{}
_ = cl.Get(context.TODO(), req.NamespacedName, foundZookeeper)
res, err = r.Reconcile(req)
res, err = r.Reconcile(req)
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
res, err = r.Reconcile(context.TODO(), req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand Down Expand Up @@ -414,19 +413,19 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next.Status.SetUpgradingConditionTrue(" ", "1")
next.Status.TargetVersion = "0.2.7"
st := zk.MakeStatefulSet(z)
cl = fake.NewFakeClient([]runtime.Object{next, st}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, st).Build()
st = &appsv1.StatefulSet{}
err = cl.Get(context.TODO(), req.NamespacedName, st)
//changing the Revision value to simulate the upgrade scenario
// changing the Revision value to simulate the upgrade scenario
st.Status.CurrentRevision = "currentRevision"
st.Status.UpdateRevision = "updateRevision"
st.Status.UpdatedReplicas = 2
cl.Status().Update(context.TODO(), st)
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
//sleeping for 3 seconds
res, err = r.Reconcile(context.TODO(), req)
// sleeping for 3 seconds
time.Sleep(3 * time.Second)
//checking if more than 2 secs have passed from the last update time
// checking if more than 2 secs have passed from the last update time
err = checkSyncTimeout(next, " ", 1, 2*time.Second)

})
Expand Down Expand Up @@ -458,9 +457,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next.Status.TargetVersion = ""
next.Status.IsClusterInUpgradingState()
st := zk.MakeStatefulSet(z)
cl = fake.NewFakeClient([]runtime.Object{next, st}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, st).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand All @@ -482,10 +481,10 @@ var _ = Describe("ZookeeperCluster Controller", func() {
BeforeEach(func() {
z.WithDefaults()
z.Status.Init()
cl = fake.NewFakeClient(z)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(z).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
req.NamespacedName.Namespace = "temp"
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})
It("should have false in reconcile result", func() {
Ω(res.Requeue).To(Equal(false))
Expand All @@ -503,9 +502,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
BeforeEach(func() {
z.WithDefaults()
z.Status.Init()
cl = fake.NewFakeClient(z)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(z).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand Down Expand Up @@ -576,9 +575,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next := z.DeepCopy()
next.Spec.Ports[0].ContainerPort = 2182
svc := zk.MakeClientService(z)
cl = fake.NewFakeClient([]runtime.Object{next, svc}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, svc).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
})

It("should not raise an error", func() {
Expand All @@ -594,9 +593,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
BeforeEach(func() {
z.WithDefaults()
z.Spec.Persistence = nil
cl = fake.NewFakeClient(z)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(z).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
err = r.reconcileFinalizers(z)
// update deletion timestamp
_ = cl.Get(context.TODO(), req.NamespacedName, z)
Expand All @@ -618,7 +617,7 @@ var _ = Describe("ZookeeperCluster Controller", func() {
BeforeEach(func() {
z.WithDefaults()
z.Spec.Persistence = nil
cl = fake.NewFakeClient(z)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(z).Build()
})
It("should have 1 finalizer, should not raise an error", func() {
config.DisableFinalizer = false
Expand Down Expand Up @@ -693,9 +692,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
next = z.DeepCopy()
next.Spec.TriggerRollingRestart = true
svc = zk.MakeClientService(z)
cl = fake.NewFakeClient([]runtime.Object{next, svc}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, svc).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
err = cl.Get(context.TODO(), req.NamespacedName, foundZk)
})

Expand All @@ -713,9 +712,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {

next.Spec.TriggerRollingRestart = false
svc = zk.MakeClientService(z)
cl = fake.NewFakeClient([]runtime.Object{next, svc}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, svc).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)

Ω(res.Requeue).To(Equal(false))
Ω(err).To(BeNil())
Expand All @@ -734,9 +733,8 @@ var _ = Describe("ZookeeperCluster Controller", func() {
// update the crd instance
next.Spec.TriggerRollingRestart = false
svc = zk.MakeClientService(z)
cl = fake.NewFakeClient([]runtime.Object{next, svc}...)
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
err = cl.Get(context.TODO(), req.NamespacedName, foundZk)

// check that restartTime was not updated
Expand All @@ -752,9 +750,9 @@ var _ = Describe("ZookeeperCluster Controller", func() {
// update the crd instance to trigger rolling restart
next.Spec.TriggerRollingRestart = true
svc = zk.MakeClientService(z)
cl = fake.NewFakeClient([]runtime.Object{next, svc}...)
cl = fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(next, svc).Build()
r = &ZookeeperClusterReconciler{Client: cl, Scheme: s, ZkClient: mockZkClient}
res, err = r.Reconcile(req)
res, err = r.Reconcile(context.TODO(), req)
err = cl.Get(context.TODO(), req.NamespacedName, foundZk)

// check that restartTime was updated
Expand Down
Loading