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

feat: Add Apigee instance controller #3554

Conversation

jasonvigil
Copy link
Collaborator

@jasonvigil jasonvigil commented Jan 29, 2025

This PR adds the mappers, controller, and records GCP interaction for ApigeeInstance. MockGCP tests will come in a separate PR.

@jasonvigil jasonvigil force-pushed the apigee-instance-controller branch 2 times, most recently from 774c8a3 to a4eed02 Compare January 30, 2025 23:14
@jasonvigil jasonvigil changed the title [WIP] Add Apigee instance controller feat: Add Apigee instance controller Jan 30, 2025
Copy link
Collaborator

@yuwenma yuwenma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/assign @jingyih

A few nits but overall looks great on my side. Can I have @jingyih to take another pass?

return mapCtx.Err()
}

if resource.AccessLoggingConfig != nil && !reflect.DeepEqual(resource.AccessLoggingConfig, a.actual.AccessLoggingConfig) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

op, err := a.instancesClient.Delete(a.id.String()).Context(ctx).Do()
if err != nil {
if direct.IsNotFound(err) {
// Return success if not found (assume it was already deleted)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding a log?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a new idea / pattern to add a log here? Should we update the template / existing controllers for this?

return true, nil
}

func (a *ApigeeInstanceAdapter) waitForOp(ctx context.Context, op *api.GoogleLongrunningOperation) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be an individual function. And suggest moving it to the controller/direct/common lib for sharing purpose.

out.AccessLoggingConfig = AccessLoggingConfig_ToAPI(mapCtx, in.AccessLoggingConfig)
out.ConsumerAcceptList = in.ConsumerAcceptList
out.Description = direct.ValueOf(in.Description)
// MISSING: DiskEncryptionKeyName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check, do you have a NOTYET comment for this field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mapper for this needs to be implemented. Will fix.

--api-version apigee.cnrm.cloud.google.com/v1alpha1 \
--kind ApigeeInstance \
--proto-resource GoogleCloudApigeeV1Instance

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to update this file. It is just an example (or is it a requirement now?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah let's not add generate-controller command.

Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: yuwenma

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

}

func (a *ApigeeInstanceAdapter) waitForOp(ctx context.Context, op *api.GoogleLongrunningOperation) error {
for {
Copy link
Collaborator

@jingyih jingyih Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably create a helper function which

  • respect the ctx timeout
  • take a input timeout

Something like this (AI generated)

func waitUntil(ctx context.Context, timeout time.Duration, condition func() bool) error {
   ctx, cancel := context.WithTimeout(context.Background(), timeout)
   defer cancel()

   ticker := time.NewTicker(100 * time.Millisecond)
   defer ticker.Stop()

   for {
       select {
       case <-ctx.Done():
           if err := ctx.Err(); err == context.DeadlineExceeded {
               return fmt.Errorf("timeout exceeded")
           }
           return ctx.Err()
       case <-ticker.C:
           if condition() {
               return nil
           }
       }
   }
}

The pulling interval could also be customized via input

Copy link
Collaborator Author

@jasonvigil jasonvigil Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The waitForOp respects the context also, no? In the operationsClient.Get(...).Context(ctx).Do(). It may wait for up to an additional 2 seconds, but the function will return (with an error) when the context is cancelled.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the current implementation of waitForOp does respect the context's timeout and cancellation. If we were to create a helper function that accepts an arbitrary input function (not just "a.operationsClient.Get"), that function may or may not respect the context. Not saying we need to create one—just an idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up going with a variant of this idea. Thanks for the recommendation.

out.PeeringCIDRRange = direct.LazyPtr(in.PeeringCidrRange)
return out
}
func ApigeeInstanceSpec_ToAPI(mapCtx *direct.MapContext, in *krm.ApigeeInstanceSpec) *pb.GoogleCloudApigeeV1Instance {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the mapping function for diskEncryptionKMSCryptoKeyRef?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, not implemented yet. Will add it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this mapper, good catch

@jasonvigil jasonvigil force-pushed the apigee-instance-controller branch from a4eed02 to 7dc778b Compare February 3, 2025 20:55
@jasonvigil jasonvigil requested review from jingyih and yuwenma February 3, 2025 23:01
Copy link
Collaborator

@jingyih jingyih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Feb 3, 2025
@google-oss-prow google-oss-prow bot merged commit 2456040 into GoogleCloudPlatform:master Feb 3, 2025
18 checks passed
@jasonvigil jasonvigil deleted the apigee-instance-controller branch February 3, 2025 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants