Skip to content

Commit 5eea60d

Browse files
authored
Update condition lib to use v2 (#61)
The v2 OperatorCondition CRD was introduced to the operator-framework/api repository. This change updates the condition library to consume the new changes.
1 parent d1cc870 commit 5eea60d

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

conditions/conditions.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"fmt"
2020
"os"
2121

22-
apiv1 "github.com/operator-framework/api/pkg/operators/v1"
22+
apiv2 "github.com/operator-framework/api/pkg/operators/v2"
2323
"github.com/operator-framework/operator-lib/internal/utils"
2424
"k8s.io/apimachinery/pkg/api/meta"
2525
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -46,7 +46,7 @@ const (
4646
// conditionType in the OperatorCondition CR.
4747
type condition struct {
4848
namespacedName types.NamespacedName
49-
condType apiv1.ConditionType
49+
condType apiv2.ConditionType
5050
client client.Client
5151
}
5252

@@ -55,7 +55,7 @@ var _ Condition = &condition{}
5555
// NewCondition returns a new Condition interface using the provided client
5656
// for the specified conditionType. The condition will internally fetch the namespacedName
5757
// of the operatorConditionCRD.
58-
func NewCondition(cl client.Client, condType apiv1.ConditionType) (Condition, error) {
58+
func NewCondition(cl client.Client, condType apiv2.ConditionType) (Condition, error) {
5959
objKey, err := GetNamespacedName()
6060
if err != nil {
6161
return nil, err
@@ -69,12 +69,12 @@ func NewCondition(cl client.Client, condType apiv1.ConditionType) (Condition, er
6969

7070
// Get implements conditions.Get
7171
func (c *condition) Get(ctx context.Context) (*metav1.Condition, error) {
72-
operatorCond := &apiv1.OperatorCondition{}
72+
operatorCond := &apiv2.OperatorCondition{}
7373
err := c.client.Get(ctx, c.namespacedName, operatorCond)
7474
if err != nil {
7575
return nil, ErrNoOperatorCondition
7676
}
77-
con := meta.FindStatusCondition(operatorCond.Status.Conditions, string(c.condType))
77+
con := meta.FindStatusCondition(operatorCond.Spec.Conditions, string(c.condType))
7878

7979
if con == nil {
8080
return nil, fmt.Errorf("conditionType %v not found", c.condType)
@@ -84,7 +84,7 @@ func (c *condition) Get(ctx context.Context) (*metav1.Condition, error) {
8484

8585
// Set implements conditions.Set
8686
func (c *condition) Set(ctx context.Context, status metav1.ConditionStatus, option ...Option) error {
87-
operatorCond := &apiv1.OperatorCondition{}
87+
operatorCond := &apiv2.OperatorCondition{}
8888
err := c.client.Get(ctx, c.namespacedName, operatorCond)
8989
if err != nil {
9090
return ErrNoOperatorCondition
@@ -100,7 +100,7 @@ func (c *condition) Set(ctx context.Context, status metav1.ConditionStatus, opti
100100
opt(newCond)
101101
}
102102
}
103-
meta.SetStatusCondition(&operatorCond.Status.Conditions, *newCond)
103+
meta.SetStatusCondition(&operatorCond.Spec.Conditions, *newCond)
104104
err = c.client.Status().Update(ctx, operatorCond)
105105
if err != nil {
106106
return err

conditions/conditions_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
. "github.com/onsi/ginkgo"
2323
. "github.com/onsi/gomega"
24-
apiv1 "github.com/operator-framework/api/pkg/operators/v1"
24+
apiv2 "github.com/operator-framework/api/pkg/operators/v2"
2525
"k8s.io/apimachinery/pkg/api/meta"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/runtime"
@@ -32,8 +32,8 @@ import (
3232
)
3333

3434
const (
35-
conditionFoo apiv1.ConditionType = "conditionFoo"
36-
conditionBar apiv1.ConditionType = "conditionBar"
35+
conditionFoo apiv2.ConditionType = "conditionFoo"
36+
conditionBar apiv2.ConditionType = "conditionBar"
3737
)
3838

3939
var _ = Describe("Condition", func() {
@@ -46,7 +46,7 @@ var _ = Describe("Condition", func() {
4646

4747
BeforeEach(func() {
4848
sch := runtime.NewScheme()
49-
err = apiv1.AddToScheme(sch)
49+
err = apiv2.AddToScheme(sch)
5050
Expect(err).NotTo(HaveOccurred())
5151
cl = fake.NewClientBuilder().WithScheme(sch).Build()
5252
})
@@ -75,17 +75,17 @@ var _ = Describe("Condition", func() {
7575
})
7676

7777
Describe("Get/Set", func() {
78-
var operatorCond *apiv1.OperatorCondition
78+
var operatorCond *apiv2.OperatorCondition
7979

8080
objKey := types.NamespacedName{
8181
Name: "operator-condition-test",
8282
Namespace: ns,
8383
}
8484

8585
BeforeEach(func() {
86-
operatorCond = &apiv1.OperatorCondition{
86+
operatorCond = &apiv2.OperatorCondition{
8787
ObjectMeta: metav1.ObjectMeta{Name: "operator-condition-test", Namespace: ns},
88-
Status: apiv1.OperatorConditionStatus{
88+
Spec: apiv2.OperatorConditionSpec{
8989
Conditions: []metav1.Condition{
9090
{
9191
Type: string(conditionFoo),
@@ -107,7 +107,7 @@ var _ = Describe("Condition", func() {
107107

108108
// create a new client
109109
sch := runtime.NewScheme()
110-
err = apiv1.AddToScheme(sch)
110+
err = apiv2.AddToScheme(sch)
111111
Expect(err).NotTo(HaveOccurred())
112112
cl = fake.NewClientBuilder().WithScheme(sch).Build()
113113

@@ -171,12 +171,12 @@ var _ = Describe("Condition", func() {
171171
Expect(err).NotTo(HaveOccurred())
172172

173173
By("fetching the condition from cluster")
174-
op := &apiv1.OperatorCondition{}
174+
op := &apiv2.OperatorCondition{}
175175
err = cl.Get(ctx, objKey, op)
176176
Expect(err).NotTo(HaveOccurred())
177177

178178
By("checking if the condition has been updated")
179-
res := op.Status.Conditions[0]
179+
res := op.Spec.Conditions[0]
180180
Expect(res.Message).To(BeEquivalentTo("test"))
181181
Expect(res.Status).To(BeEquivalentTo(metav1.ConditionFalse))
182182
Expect(res.Reason).To(BeEquivalentTo("not_in_foo_state"))
@@ -190,12 +190,12 @@ var _ = Describe("Condition", func() {
190190
Expect(err).NotTo(HaveOccurred())
191191

192192
By("fetching the condition from cluster")
193-
op := &apiv1.OperatorCondition{}
193+
op := &apiv2.OperatorCondition{}
194194
err = cl.Get(ctx, objKey, op)
195195
Expect(err).NotTo(HaveOccurred())
196196

197197
By("checking if the condition has been updated")
198-
res := op.Status.Conditions
198+
res := op.Spec.Conditions
199199
Expect(len(res)).To(BeEquivalentTo(2))
200200
Expect(meta.IsStatusConditionTrue(res, string(conditionBar))).To(BeTrue())
201201
})

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0
3636
github.com/NYTimes/gziphandler v1.1.1/go.mod h1:n/CVRwUEOgIxrgPvAQhUUr9oeUtvrhMomdKFjzJNB0c=
3737
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
3838
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
39+
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
3940
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
4041
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
4142
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=

0 commit comments

Comments
 (0)