-
Notifications
You must be signed in to change notification settings - Fork 43
Update condition lib to use v2 #61
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ import ( | |
"fmt" | ||
"os" | ||
|
||
apiv1 "github.com/operator-framework/api/pkg/operators/v1" | ||
apiv2 "github.com/operator-framework/api/pkg/operators/v2" | ||
"github.com/operator-framework/operator-lib/internal/utils" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -46,7 +46,7 @@ const ( | |
// conditionType in the OperatorCondition CR. | ||
type condition struct { | ||
namespacedName types.NamespacedName | ||
condType apiv1.ConditionType | ||
condType apiv2.ConditionType | ||
client client.Client | ||
} | ||
|
||
|
@@ -55,7 +55,7 @@ var _ Condition = &condition{} | |
// NewCondition returns a new Condition interface using the provided client | ||
// for the specified conditionType. The condition will internally fetch the namespacedName | ||
// of the operatorConditionCRD. | ||
func NewCondition(cl client.Client, condType apiv1.ConditionType) (Condition, error) { | ||
func NewCondition(cl client.Client, condType apiv2.ConditionType) (Condition, error) { | ||
objKey, err := GetNamespacedName() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -69,12 +69,12 @@ func NewCondition(cl client.Client, condType apiv1.ConditionType) (Condition, er | |
|
||
// Get implements conditions.Get | ||
func (c *condition) Get(ctx context.Context) (*metav1.Condition, error) { | ||
operatorCond := &apiv1.OperatorCondition{} | ||
operatorCond := &apiv2.OperatorCondition{} | ||
err := c.client.Get(ctx, c.namespacedName, operatorCond) | ||
if err != nil { | ||
return nil, ErrNoOperatorCondition | ||
} | ||
con := meta.FindStatusCondition(operatorCond.Status.Conditions, string(c.condType)) | ||
con := meta.FindStatusCondition(operatorCond.Spec.Conditions, string(c.condType)) | ||
|
||
if con == nil { | ||
return nil, fmt.Errorf("conditionType %v not found", c.condType) | ||
|
@@ -84,7 +84,7 @@ func (c *condition) Get(ctx context.Context) (*metav1.Condition, error) { | |
|
||
// Set implements conditions.Set | ||
func (c *condition) Set(ctx context.Context, status metav1.ConditionStatus, option ...Option) error { | ||
operatorCond := &apiv1.OperatorCondition{} | ||
operatorCond := &apiv2.OperatorCondition{} | ||
err := c.client.Get(ctx, c.namespacedName, operatorCond) | ||
if err != nil { | ||
return ErrNoOperatorCondition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider returning the original error, or at least wrap it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I support this change, but recommend doing so in a separate commit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #65 |
||
|
@@ -100,7 +100,7 @@ func (c *condition) Set(ctx context.Context, status metav1.ConditionStatus, opti | |
opt(newCond) | ||
} | ||
} | ||
meta.SetStatusCondition(&operatorCond.Status.Conditions, *newCond) | ||
meta.SetStatusCondition(&operatorCond.Spec.Conditions, *newCond) | ||
err = c.client.Status().Update(ctx, operatorCond) | ||
if err != nil { | ||
return err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ import ( | |
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
apiv1 "github.com/operator-framework/api/pkg/operators/v1" | ||
apiv2 "github.com/operator-framework/api/pkg/operators/v2" | ||
"k8s.io/apimachinery/pkg/api/meta" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
|
@@ -32,8 +32,8 @@ import ( | |
) | ||
|
||
const ( | ||
conditionFoo apiv1.ConditionType = "conditionFoo" | ||
conditionBar apiv1.ConditionType = "conditionBar" | ||
conditionFoo apiv2.ConditionType = "conditionFoo" | ||
conditionBar apiv2.ConditionType = "conditionBar" | ||
) | ||
|
||
var _ = Describe("Condition", func() { | ||
|
@@ -46,7 +46,7 @@ var _ = Describe("Condition", func() { | |
|
||
BeforeEach(func() { | ||
sch := runtime.NewScheme() | ||
err = apiv1.AddToScheme(sch) | ||
err = apiv2.AddToScheme(sch) | ||
Expect(err).NotTo(HaveOccurred()) | ||
cl = fake.NewClientBuilder().WithScheme(sch).Build() | ||
}) | ||
|
@@ -75,17 +75,17 @@ var _ = Describe("Condition", func() { | |
}) | ||
|
||
Describe("Get/Set", func() { | ||
var operatorCond *apiv1.OperatorCondition | ||
var operatorCond *apiv2.OperatorCondition | ||
|
||
objKey := types.NamespacedName{ | ||
Name: "operator-condition-test", | ||
Namespace: ns, | ||
} | ||
|
||
BeforeEach(func() { | ||
operatorCond = &apiv1.OperatorCondition{ | ||
operatorCond = &apiv2.OperatorCondition{ | ||
ObjectMeta: metav1.ObjectMeta{Name: "operator-condition-test", Namespace: ns}, | ||
Status: apiv1.OperatorConditionStatus{ | ||
Spec: apiv2.OperatorConditionSpec{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a non-blocker, but it would be helpful to have If not the other option is - to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in this release: https://github.com/operator-framework/api/releases/tag/v0.9.1 |
||
Conditions: []metav1.Condition{ | ||
{ | ||
Type: string(conditionFoo), | ||
|
@@ -107,7 +107,7 @@ var _ = Describe("Condition", func() { | |
|
||
// create a new client | ||
sch := runtime.NewScheme() | ||
err = apiv1.AddToScheme(sch) | ||
err = apiv2.AddToScheme(sch) | ||
Expect(err).NotTo(HaveOccurred()) | ||
cl = fake.NewClientBuilder().WithScheme(sch).Build() | ||
|
||
|
@@ -171,12 +171,12 @@ var _ = Describe("Condition", func() { | |
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("fetching the condition from cluster") | ||
op := &apiv1.OperatorCondition{} | ||
op := &apiv2.OperatorCondition{} | ||
err = cl.Get(ctx, objKey, op) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("checking if the condition has been updated") | ||
res := op.Status.Conditions[0] | ||
res := op.Spec.Conditions[0] | ||
Expect(res.Message).To(BeEquivalentTo("test")) | ||
Expect(res.Status).To(BeEquivalentTo(metav1.ConditionFalse)) | ||
Expect(res.Reason).To(BeEquivalentTo("not_in_foo_state")) | ||
|
@@ -190,12 +190,12 @@ var _ = Describe("Condition", func() { | |
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("fetching the condition from cluster") | ||
op := &apiv1.OperatorCondition{} | ||
op := &apiv2.OperatorCondition{} | ||
err = cl.Get(ctx, objKey, op) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
By("checking if the condition has been updated") | ||
res := op.Status.Conditions | ||
res := op.Spec.Conditions | ||
Expect(len(res)).To(BeEquivalentTo(2)) | ||
Expect(meta.IsStatusConditionTrue(res, string(conditionBar))).To(BeTrue()) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider returning the original error, or at least wrap it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support this change, but recommend doing so in a separate commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #65