Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijit Mukherjee <[email protected]>
  • Loading branch information
mabhi committed Feb 13, 2024
1 parent 90512b4 commit 3501d84
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions pkg/customresource/customresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Context struct {
APIExtensionClientset apiextensionsclient.Interface
Interval time.Duration
Timeout time.Duration
ParentContext contextpkg.Context
Context contextpkg.Context
}

// CreateCustomResources creates the given custom resources and waits for them to initialize
Expand Down Expand Up @@ -125,21 +125,21 @@ func createCRD(context Context, resource CustomResource) error {
return errors.Wrap(err, "Getting CRD object from CRD bytes")
}

_, err = context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Create(context.ParentContext, crd, metav1.CreateOptions{})
_, err = context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Create(context.Context, crd, metav1.CreateOptions{})
if err != nil {
if !apierrors.IsAlreadyExists(err) {
return errors.Errorf("Failed to create %s CRD. %+v", resource.Name, err)
}

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
// if CRD already exists, get the resource version and create the CRD with that resource version
c, err := context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.ParentContext, crd.Name, metav1.GetOptions{})
c, err := context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.Context, crd.Name, metav1.GetOptions{})
if err != nil {
return err
}

crd.ResourceVersion = c.ResourceVersion
_, err = context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Update(context.ParentContext, crd, metav1.UpdateOptions{})
_, err = context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Update(context.Context, crd, metav1.UpdateOptions{})
if err != nil {
return err
}
Expand All @@ -159,8 +159,8 @@ func rawCRDFromFile(path string) ([]byte, error) {

func waitForCRDInit(context Context, resource CustomResource) error {
crdName := fmt.Sprintf("%s.%s", resource.Plural, resource.Group)
return wait.PollUntilContextTimeout(context.ParentContext, context.Interval, context.Timeout, false, func(contextpkg.Context) (bool, error) {
crd, err := context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.ParentContext, crdName, metav1.GetOptions{})
return wait.PollUntilContextTimeout(context.Context, context.Interval, context.Timeout, false, func(contextpkg.Context) (bool, error) {
crd, err := context.APIExtensionClientset.ApiextensionsV1().CustomResourceDefinitions().Get(context.Context, crdName, metav1.GetOptions{})
if err != nil {
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func newOpKitContext(config *rest.Config, ctx context.Context) (*customresource.
APIExtensionClientset: apiExtClientset,
Interval: 500 * time.Millisecond,
Timeout: 60 * time.Second,
ParentContext: ctx,
Context: ctx,
}, nil
}

Expand Down

0 comments on commit 3501d84

Please sign in to comment.