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

apis: ApigeeEnvgroupAttachment #3605

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

acpana
Copy link
Collaborator

@acpana acpana commented Feb 5, 2025

Adds direct style APIs for the ApigeeEnvgroupAttachment. This is an alpha resource, still running over the TF controller.

Next PR:

  • add a direct controoler
  • change envgroup and environment fields to references!

@acpana acpana requested a review from yuwenma February 5, 2025 01:07
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign cheftako for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@acpana acpana requested a review from jasonvigil February 5, 2025 01:08
Signed-off-by: Alex Pana <[email protected]>
if obj.Spec.Envgroup == "" {
return nil, fmt.Errorf("spec.envgroup cannot be empty")
}
if obj.Spec.Environment == "" {
Copy link
Collaborator

@jasonvigil jasonvigil Feb 5, 2025

Choose a reason for hiding this comment

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

I don't think it is necessary to validate this here? Because spec.environment is not part of the identity

// holds the GCP identifier for the KRM object.
type ApigeeEnvgroupAttachmentRef struct {
// A reference to an externally managed ApigeeEnvgroupAttachment resource.
// Should be in the format "projects/*/locations/global/envgroups/*/attachments/*".
Copy link
Collaborator

Choose a reason for hiding this comment

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

This format looks incorrect to me, shouldn't it be in the pattern of organizations/{{organizationID}}/envgroups/{{envgroupID}}/attachments/{{attachmentID}} ?

func ParseApigeeEnvgroupAttachmentExternalRef(external string) (parent *EnvgroupAttachmentParent, resourceID string, err error) {
tokens := strings.Split(external, "/")
if len(tokens) != 6 {
return nil, "", fmt.Errorf("invalid external format: %s, expecting organizations/*/envgroups/*/attachments/*", external)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency with #3398, I think we should use the same pattern (using {{xyzID}} instead of *)

if err != nil {
return nil, err
}
if actualParent.Envgroup != obj.Spec.Envgroup {
Copy link
Collaborator

Choose a reason for hiding this comment

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

tiny nit, feels a bit weird to compare these fields out-of-order. i.e. envgroup -> org -> id instead of org -> envgroup -> id

// +required
OrganizationRef *refv1alpha1.ApigeeOrganizationRef `json:"organizationRef"`

// Immutable. The Apigee environment to attach to.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought this resource attaches an environment to an envgroup. Not the other way around. Where did this comment come from? Was it originally from the API? In any case, I think we should update this.

// Immutable. The Apigee environment to attach to.
Environment string `json:"environment"`

// Immutable. The Apigee environment group which will host the environment.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, would put this field before Environment, because Envgroup is part of the parent.

}

// ApigeeEnvgroupAttachmentStatus defines the observed state of ApigeeEnvgroupAttachment
type ApigeeEnvgroupAttachmentStatus struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be an observedState.createdAt field?

int64 created_at = 1 [json_name="createdAt"];

// holds the GCP identifier for the KRM object.
type ApigeeEnvironmentRef struct {
// A reference to an externally managed ApigeeEnvironment resource.
// Should be in the format "projects/*/environments/*".
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should have format starting with organizations/{{organizationID}}/..., no?

return "", fmt.Errorf("reading status.externalRef: %w", err)
}
if !found {
// todo acpana careful to deal with this
Copy link
Collaborator

Choose a reason for hiding this comment

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

In case you are not the next person who hits this issue, could you please put a more descriptive comment? Would suggest linking to bug / ticket and including some details around expected issue behavior, resolution hints, etc.

return r.External, nil
}

// todo acpana this should be in a _identity.go file eventually
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we do this now?

tokens := strings.Split(external, "/")

if len(tokens) != 4 || tokens[0] != "organizations" || tokens[2] != "environments" {
return "", "", fmt.Errorf("external should be organizations/{organization}/environments/{environment}, got: %s", external)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For consistency with other resources, we should use {{organizationID}} (double curly)

OrganizationRef *refv1alpha1.ApigeeOrganizationRef `json:"organizationRef"`

// Immutable. The Apigee environment to attach to.
Environment string `json:"environment"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use a reference type here

Environment string `json:"environment"`

// Immutable. The Apigee environment group which will host the environment.
Envgroup string `json:"envgroup"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, this should be a reference type, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants