Skip to content

Commit

Permalink
Migrate test utils to actuator-pkg repository
Browse files Browse the repository at this point in the history
  • Loading branch information
RadekManak committed Feb 9, 2023
1 parent 2a90938 commit 535a6cc
Show file tree
Hide file tree
Showing 72 changed files with 1,649 additions and 1,725 deletions.
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ require (
github.com/go-test/deep v1.1.0
github.com/golang/mock v1.6.0
github.com/golangci/golangci-lint v1.50.1
github.com/onsi/ginkgo/v2 v2.6.1
github.com/onsi/gomega v1.24.2
github.com/onsi/ginkgo/v2 v2.7.0
github.com/onsi/gomega v1.26.0
github.com/openshift/api v0.0.0-20230208093943-11903e0431cd
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084
github.com/openshift/cluster-api-actuator-pkg/testutils v0.0.0-00010101000000-000000000000
github.com/openshift/library-go v0.0.0-20230130232623-47904dd9ff5a
github.com/spf13/pflag v1.0.5
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/component-base v0.26.1
k8s.io/klog/v2 v2.90.0
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
k8s.io/utils v0.0.0-20230115233650-391b47cb4029
sigs.k8s.io/controller-runtime v0.14.4
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230127152628-dd6bafd4572e
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230131074648-f5014c077fc3
sigs.k8s.io/controller-tools v0.11.3
)

replace github.com/openshift/cluster-api-actuator-pkg/testutils => github.com/RadekManak/cluster-api-actuator-pkg/testutils v0.0.0-20230201125136-02f668983c91

require (
4d63.com/gochecknoglobals v0.1.0 // indirect
github.com/Abirdcfly/dupword v0.0.7 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3Q
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/OpenPeeDeeP/depguard v1.1.1 h1:TSUznLjvp/4IUP+OQ0t/4jF4QUyxIcVX8YnghZdunyA=
github.com/OpenPeeDeeP/depguard v1.1.1/go.mod h1:JtAMzWkmFEzDPyAd+W0NHl1lvpQKTvT9jnRVsohBKpc=
github.com/RadekManak/cluster-api-actuator-pkg/testutils v0.0.0-20230201125136-02f668983c91 h1:PI0BP9BVNfiSL+bG7cC90Fuc7I5bhi8ptBPT8lzvdck=
github.com/RadekManak/cluster-api-actuator-pkg/testutils v0.0.0-20230201125136-02f668983c91/go.mod h1:p8CKj6ENJj5euJ3Grs71A9wwzBs9EzC1BcVlHCIPJg8=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -456,8 +458,8 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/ginkgo/v2 v2.4.0/go.mod h1:iHkDK1fKGcBoEHT5W7YBq4RFWaQulw+caOMkAt4OrFo=
github.com/onsi/gomega v1.24.2 h1:J/tulyYK6JwBldPViHJReihxxZ+22FHs0piGjQAvoUE=
github.com/onsi/gomega v1.24.2/go.mod h1:gs3J10IS7Z7r7eXRoNJIrNqU4ToQukCJhFtKrWgHWnk=
github.com/onsi/gomega v1.26.0 h1:03cDLK28U6hWvCAns6NeydX3zIm4SF3ci69ulidS32Q=
github.com/onsi/gomega v1.26.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
github.com/openshift/api v0.0.0-20230208093943-11903e0431cd h1:h6PWIIAWe+RnQ7rVxyBpeHIztqWYG5K1JoVv8Twgngo=
github.com/openshift/api v0.0.0-20230208093943-11903e0431cd/go.mod h1:ctXNyWanKEjGj8sss1KjjHQ3ENKFm33FFnS5BKaIPh4=
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084 h1:66uaqNwA+qYyQDwsMWUfjjau8ezmg1dzCqub13KZOcE=
Expand Down Expand Up @@ -1076,8 +1078,8 @@ k8s.io/klog/v2 v2.90.0 h1:VkTxIV/FjRXn1fgNNcKGM8cfmL1Z33ZjXRTVxKCoF5M=
k8s.io/klog/v2 v2.90.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+OGxg8HsuBr/5f6tVAjDu6E=
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 h1:KTgPnR10d5zhztWptI952TNtt/4u5h3IzDXkdIMuo2Y=
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
k8s.io/utils v0.0.0-20230115233650-391b47cb4029 h1:L8zDtT4jrxj+TaQYD0k8KNlr556WaVQylDXswKmX+dE=
k8s.io/utils v0.0.0-20230115233650-391b47cb4029/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
mvdan.cc/gofumpt v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
mvdan.cc/gofumpt v0.4.0/go.mod h1:PljLOHDeZqgS8opHRKLzp2It2VBuSdteAgqUfzMTxlQ=
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I=
Expand All @@ -1091,8 +1093,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/controller-runtime v0.14.4 h1:Kd/Qgx5pd2XUL08eOV2vwIq3L9GhIbJ5Nxengbd4/0M=
sigs.k8s.io/controller-runtime v0.14.4/go.mod h1:WqIdsAY6JBsjfc/CqO0CORmNtoCtE4S6qbPc9s68h+0=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230127152628-dd6bafd4572e h1:zcH2EQaks41+iBg1Zm8VxrSD7S/5Mibn9Q9hL/u4fDc=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230127152628-dd6bafd4572e/go.mod h1:Lm5xRgQejdMHAz81exSpqvwEkIdTfoNtUDA6MM4kltw=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230131074648-f5014c077fc3 h1:+WOeQgey5/PCm0TxrnJWdPw+7LSzD0FTHmW94O3NVqM=
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20230131074648-f5014c077fc3/go.mod h1:Lm5xRgQejdMHAz81exSpqvwEkIdTfoNtUDA6MM4kltw=
sigs.k8s.io/controller-tools v0.11.3 h1:T1xzLkog9saiyQSLz1XOImu4OcbdXWytc5cmYsBeBiE=
sigs.k8s.io/controller-tools v0.11.3/go.mod h1:qcfX7jfcfYD/b7lAhvqAyTbt/px4GpvN88WKLFFv7p8=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/controlplanemachineset/cluster_operator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Red Hat, Inc.
Copyright 2023 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
61 changes: 32 additions & 29 deletions pkg/controllers/controlplanemachineset/cluster_operator_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 Red Hat, Inc.
Copyright 2023 Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,8 +25,11 @@ import (
configv1 "github.com/openshift/api/config/v1"
machinev1 "github.com/openshift/api/machine/v1"
machinev1beta1 "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/test"
"github.com/openshift/cluster-control-plane-machine-set-operator/pkg/test/resourcebuilder"
"github.com/openshift/cluster-api-actuator-pkg/testutils"
configv1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/config/v1"
corev1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/core/v1"
machinev1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/machine/v1"
metav1resourcebuilder "github.com/openshift/cluster-api-actuator-pkg/testutils/resourcebuilder/meta/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -35,14 +38,14 @@ import (
)

var (
statusConditionAvailable = resourcebuilder.StatusCondition().WithType(conditionAvailable).WithStatus(metav1.ConditionTrue).WithReason(reasonAllReplicasAvailable).Build()
statusConditionNotAvailable = resourcebuilder.StatusCondition().WithType(conditionAvailable).WithStatus(metav1.ConditionFalse).WithReason(reasonUnavailableReplicas).WithMessage("Missing 3 available replica(s)").Build()
statusConditionAvailable = metav1resourcebuilder.Condition().WithType(conditionAvailable).WithStatus(metav1.ConditionTrue).WithReason(reasonAllReplicasAvailable).Build()
statusConditionNotAvailable = metav1resourcebuilder.Condition().WithType(conditionAvailable).WithStatus(metav1.ConditionFalse).WithReason(reasonUnavailableReplicas).WithMessage("Missing 3 available replica(s)").Build()

statusConditionProgressing = resourcebuilder.StatusCondition().WithType(conditionProgressing).WithStatus(metav1.ConditionTrue).WithReason(reasonNeedsUpdateReplicas).WithMessage("Observed 1 replica(s) in need of update").Build()
statusConditionNotProgressing = resourcebuilder.StatusCondition().WithType(conditionProgressing).WithStatus(metav1.ConditionFalse).WithReason(reasonAllReplicasUpdated).Build()
statusConditionProgressing = metav1resourcebuilder.Condition().WithType(conditionProgressing).WithStatus(metav1.ConditionTrue).WithReason(reasonNeedsUpdateReplicas).WithMessage("Observed 1 replica(s) in need of update").Build()
statusConditionNotProgressing = metav1resourcebuilder.Condition().WithType(conditionProgressing).WithStatus(metav1.ConditionFalse).WithReason(reasonAllReplicasUpdated).Build()

statusConditionDegraded = resourcebuilder.StatusCondition().WithType(conditionDegraded).WithStatus(metav1.ConditionTrue).WithReason(reasonUnmanagedNodes).WithMessage("Found 3 unmanaged node(s)").Build()
statusConditionNotDegraded = resourcebuilder.StatusCondition().WithType(conditionDegraded).WithStatus(metav1.ConditionFalse).WithReason(reasonAsExpected).Build()
statusConditionDegraded = metav1resourcebuilder.Condition().WithType(conditionDegraded).WithStatus(metav1.ConditionTrue).WithReason(reasonUnmanagedNodes).WithMessage("Found 3 unmanaged node(s)").Build()
statusConditionNotDegraded = metav1resourcebuilder.Condition().WithType(conditionDegraded).WithStatus(metav1.ConditionFalse).WithReason(reasonAsExpected).Build()
)

var _ = Describe("Cluster Operator Status with a running controller", func() {
Expand All @@ -57,7 +60,7 @@ var _ = Describe("Cluster Operator Status with a running controller", func() {

BeforeEach(func() {
By("Setting up a namespace for the test")
ns := resourcebuilder.Namespace().WithGenerateName("control-plane-machine-set-cluster-operator-").Build()
ns := corev1resourcebuilder.Namespace().WithGenerateName("control-plane-machine-set-cluster-operator-").Build()
Expect(k8sClient.Create(ctx, ns)).To(Succeed())
namespaceName = ns.GetName()

Expand Down Expand Up @@ -93,7 +96,7 @@ var _ = Describe("Cluster Operator Status with a running controller", func() {
}()

// CVO will create a blank cluster operator for us before the operator starts.
co = resourcebuilder.ClusterOperator().WithName(operatorName).Build()
co = configv1resourcebuilder.ClusterOperator().WithName(operatorName).Build()
Expect(k8sClient.Create(ctx, co)).To(Succeed())
})

Expand All @@ -103,7 +106,7 @@ var _ = Describe("Cluster Operator Status with a running controller", func() {
// Wait for the mgrDone to be closed, which will happen once the mgr has stopped
<-mgrDone

test.CleanupResources(Default, ctx, cfg, k8sClient, namespaceName,
testutils.CleanupResources(Default, ctx, cfg, k8sClient, namespaceName,
&corev1.Node{},
&configv1.ClusterOperator{},
&machinev1beta1.Machine{},
Expand All @@ -113,9 +116,9 @@ var _ = Describe("Cluster Operator Status with a running controller", func() {

Context("with no ControlPlaneMachineSet", func() {
It("Set the cluster operator available", func() {
co := resourcebuilder.ClusterOperator().WithName(operatorName).Build()
co := configv1resourcebuilder.ClusterOperator().WithName(operatorName).Build()

Eventually(komega.Object(co)).Should(HaveField("Status.Conditions", test.MatchClusterOperatorStatusConditions([]configv1.ClusterOperatorStatusCondition{
Eventually(komega.Object(co)).Should(HaveField("Status.Conditions", testutils.MatchClusterOperatorStatusConditions([]configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionTrue,
Expand Down Expand Up @@ -143,14 +146,14 @@ var _ = Describe("Cluster Operator Status with a running controller", func() {

Context("And an invalid cluster operator", func() {
BeforeEach(func() {
coStatus := resourcebuilder.ClusterOperatorStatus().Build()
coStatus := configv1resourcebuilder.ClusterOperatorStatus().Build()
Eventually(komega.UpdateStatus(co, func() {
co.Status = coStatus
})).Should(Succeed())
})

It("Set the cluster operator available", func() {
Eventually(komega.Object(co)).Should(HaveField("Status.Conditions", test.MatchClusterOperatorStatusConditions([]configv1.ClusterOperatorStatusCondition{
Eventually(komega.Object(co)).Should(HaveField("Status.Conditions", testutils.MatchClusterOperatorStatusConditions([]configv1.ClusterOperatorStatusCondition{
{
Type: configv1.OperatorAvailable,
Status: configv1.ConditionTrue,
Expand Down Expand Up @@ -183,18 +186,18 @@ var _ = Describe("Cluster Operator Status", func() {
const operatorName = "control-plane-machine-set"
var co *configv1.ClusterOperator
var reconciler *ControlPlaneMachineSetReconciler
var logger test.TestLogger
var logger testutils.TestLogger
var namespaceName string

var cpmsBuilder resourcebuilder.ControlPlaneMachineSetBuilder
var cpmsBuilder machinev1resourcebuilder.ControlPlaneMachineSetBuilder

BeforeEach(func() {
By("Setting up a namespace for the test")
ns := resourcebuilder.Namespace().WithGenerateName("control-plane-machine-set-cluster-operator-").Build()
ns := corev1resourcebuilder.Namespace().WithGenerateName("control-plane-machine-set-cluster-operator-").Build()
Expect(k8sClient.Create(ctx, ns)).To(Succeed())
namespaceName = ns.GetName()

cpmsBuilder = resourcebuilder.ControlPlaneMachineSet().WithName(clusterControlPlaneMachineSetName).WithNamespace(namespaceName)
cpmsBuilder = machinev1resourcebuilder.ControlPlaneMachineSet().WithName(clusterControlPlaneMachineSetName).WithNamespace(namespaceName)

reconciler = &ControlPlaneMachineSetReconciler{
Client: k8sClient,
Expand All @@ -204,25 +207,25 @@ var _ = Describe("Cluster Operator Status", func() {
}

// CVO will create a blank cluster operator for us before the operator starts.
co = resourcebuilder.ClusterOperator().WithName(operatorName).Build()
co = configv1resourcebuilder.ClusterOperator().WithName(operatorName).Build()
Expect(k8sClient.Create(ctx, co)).To(Succeed())

logger = test.NewTestLogger()
logger = testutils.NewTestLogger()
})

AfterEach(func() {
test.CleanupResources(Default, ctx, cfg, k8sClient, namespaceName,
testutils.CleanupResources(Default, ctx, cfg, k8sClient, namespaceName,
&configv1.ClusterOperator{},
&machinev1.ControlPlaneMachineSet{},
)
})

Context("updateClusterOperatorStatus", func() {
type updateClusterOperatorStatusTableInput struct {
cpmsBuilder resourcebuilder.ControlPlaneMachineSetInterface
cpmsBuilder machinev1resourcebuilder.ControlPlaneMachineSetInterface
expectedConditions []configv1.ClusterOperatorStatusCondition
expectedError error
expectedLogs []test.LogEntry
expectedLogs []testutils.LogEntry
}

DescribeTable("should update the cluster operator status based on the ControlPlaneMachineSet conditions", func(in updateClusterOperatorStatusTableInput) {
Expand All @@ -237,7 +240,7 @@ var _ = Describe("Cluster Operator Status", func() {
Expect(err).ToNot(HaveOccurred())
}

Eventually(komega.Object(co)).Should(HaveField("Status.Conditions", test.MatchClusterOperatorStatusConditions(in.expectedConditions)))
Eventually(komega.Object(co)).Should(HaveField("Status.Conditions", testutils.MatchClusterOperatorStatusConditions(in.expectedConditions)))
Expect(logger.Entries()).To(ConsistOf(in.expectedLogs))
Expect(cpms).To(Equal(originalCPMS), "The update functions should not modify the ControlPlaneMachineSet in any way")
},
Expand Down Expand Up @@ -267,7 +270,7 @@ var _ = Describe("Cluster Operator Status", func() {
Message: "cluster operator is upgradable",
},
},
expectedLogs: []test.LogEntry{
expectedLogs: []testutils.LogEntry{
{
Level: 4,
Message: "Syncing cluster operator status",
Expand Down Expand Up @@ -307,7 +310,7 @@ var _ = Describe("Cluster Operator Status", func() {
Message: "cluster operator is not upgradable",
},
},
expectedLogs: []test.LogEntry{
expectedLogs: []testutils.LogEntry{
{
Level: 4,
Message: "Syncing cluster operator status",
Expand Down Expand Up @@ -347,7 +350,7 @@ var _ = Describe("Cluster Operator Status", func() {
Message: "cluster operator is not upgradable",
},
},
expectedLogs: []test.LogEntry{
expectedLogs: []testutils.LogEntry{
{
Level: 4,
Message: "Syncing cluster operator status",
Expand Down
Loading

0 comments on commit 535a6cc

Please sign in to comment.