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

Migrate BQ reservation from TF-based to direct controller v1alpha1 #3569

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

Conversation

600lyy
Copy link
Member

@600lyy 600lyy commented Jan 30, 2025

Change description

  1. Generated API and CRD
  2. Added resource mappings between KRM and API
  3. Generated direct controller

Tests you have done

KCC_USE_DIRECT_RECONCILERS=BigqueryReservationReservation hack/compare-mock fixture/bigqueryreservationenterprise

KCC_USE_DIRECT_RECONCILERS=BigqueryReservationReservation hack/compare-mock fixture/bigqueryreservationstandard

  • Run make ready-pr to ensure this PR is ready for review.
  • Perform necessary E2E testing for changed resources.

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 justinsb 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

@600lyy 600lyy force-pushed the bq-reservation-cross-region branch 2 times, most recently from e5c94ae to 44a4afc Compare February 3, 2025 15:51
@jingyih
Copy link
Collaborator

jingyih commented Feb 3, 2025

Can we rerun the test to update the golden object?

https://github.com/GoogleCloudPlatform/k8s-config-connector/actions/runs/13117527154/job/36595380463#step:4:17534

The diff looks fine to me. The default value of annotation "cnrm.cloud.google.com/management-conflict-prevention-policy" is "none".

    utils.go:235: FAIL: unexpected diff in /home/runner/work/k8s-config-connector/k8s-config-connector/pkg/test/resourcefixture/testdata/basic/bigqueryreservation/v1alpha1/bigqueryreservationreservation/bigqueryreservationenterprise/_generated_object_bigqueryreservationenterprise.golden.yaml:   map[string]any{
          	"apiVersion": string("bigqueryreservation.cnrm.cloud.google.com/v1alpha1"),
          	"kind":       string("BigQueryReservationReservation"),
          	"metadata": map[string]any{
        - 		"annotations": map[string]any{"cnrm.cloud.google.com/management-conflict-prevention-policy": string("none")},
          		"finalizers":  []any{string("cnrm.cloud.google.com/finalizer"), string("cnrm.cloud.google.com/deletion-defender")},
          		"generation":  float64(2),
          		... // 3 identical entries
          	},
          	"spec":   map[string]any{"autoscale": map[string]any{"maxSlots": float64(100)}, "concurrency": float64(1), "edition": string("ENTERPRISE"), "ignoreIdleSlots": bool(true), ...},
          	"status": map[string]any{"conditions": []any{map[string]any{"lastTransitionTime": string("1970-01-01T00:00:00Z"), "message": string("The resource is up to date"), "reason": string("UpToDate"), "status": string("True"), ...}}, "externalRef": string("projects/${projectId}/locations/us-west2/reservations/bigqueryre"...), "observedGeneration": float64(2), "observedState": map[string]any{}},
          }

// to create a failover reservation or in update reservation calls to convert
// a non-failover reservation to a failover reservation(or vice versa).
// +kcc:proto:field=google.cloud.bigquery.reservation.v1.Reservation.secondary_location
SecondaryLocation *string `json:"secondaryLocation,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure how primaryLocation, secondaryLocation, and originalPrimaryLocation are being used. Could we capture their usage by adding a test? Alternatively, we could comment them out for now and reintroduce them later.

Copy link
Member Author

Choose a reason for hiding this comment

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

These fields are being used only for the BQ managed DR when the BQ edition is enterprise-plus.
I will be adding more tests to capture different scenarios

Copy link
Member Author

@600lyy 600lyy Feb 4, 2025

Choose a reason for hiding this comment

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

primaryLocation and originalPrimaryLocation are fine, they're both output-only. So when the secondaryLocation is being specified, this means the managed DR is enabled, in this case the API will return primaryLocation, secondaryLocation and originalPrimaryLocation in the response.

see the http.log:

  "originalPrimaryLocation": "us-west2",
  "primaryLocation": "us-west2",
  "secondaryLocation": "us-east1",

The only tricky part is secondaryLocation. According to the API, users can set this in create reservation calls to create a failover reservation or in update reservation calls to convert a non-failover reservation to a failover reservation(or vice versa).

Copy link
Collaborator

Choose a reason for hiding this comment

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

According to the API, users can set this in create reservation calls to create a failover reservation or in update reservation calls to convert a non-failover reservation to a failover reservation(or vice versa).

Can we add one test case to convert a failover reservation to a non-failover; and one test case to convert a non failover to a failover?

Copy link
Member Author

@600lyy 600lyy Feb 5, 2025

Choose a reason for hiding this comment

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

Uploaded two tests to capture the http logs from real gcp. Turns out that API doesn't change the output returned to the PATCH requests

commit 7

Copy link
Collaborator

Choose a reason for hiding this comment

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

Turns out that API doesn't change the output returned to the PATCH requests

I left a comment regarding updateMask in the http PATCH request. I think it is related to the behavior you observed here. Let's fix the update logic in controller first.

Copy link
Member Author

@600lyy 600lyy Feb 7, 2025

Choose a reason for hiding this comment

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

Thanks!

I've fixed the updateMask and rerun tests against both mockgcp and real target.

  • Fixed the update Mask
    [commit 9] (74a97ee)

  • Fixed the morkgcp
    [commit 13] (c3ad7e0)

package v1alpha1

// +kcc:proto=google.cloud.bigquery.reservation.v1.Reservation
type Reservation struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you record the controller builder commands used for types and mappings in generate.sh? Also, when rerunning the script, it should remove the type Reservation struct since it already exists in the reservation_types file.

https://github.com/GoogleCloudPlatform/k8s-config-connector/blob/master/dev/tools/controllerbuilder/generate.sh

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a bit confused, do you mean that I should rerun the command below to generate the type for reservation?

go run main.go generate-controller \
     --service google.cloud.bigquery.reservation.v1 \
     --api-version "bigqueryreservation.cnrm.cloud.google.com/v1alpha1" \
     --kind BigqueryReservationReservation \
     --proto-resource Reservation

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah rerunning the command should help cleanup the unnecessary code in types.generated.go.

Copy link
Member Author

@600lyy 600lyy Feb 5, 2025

Choose a reason for hiding this comment

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

Nothing has changed after rerunning the command, this is the output:

file /usr/local/google/home/luyul/go/src/github.com/600lyy/k8s-config-connector/pkg/controller/direct/bigqueryreservation/reservation_controller.go already exists, skipping
New controller Reservation has been registered.

@600lyy 600lyy force-pushed the bq-reservation-cross-region branch from ba8be10 to a0f4a2c Compare February 4, 2025 14:01
@600lyy 600lyy closed this Feb 4, 2025
@600lyy 600lyy reopened this Feb 4, 2025
@600lyy 600lyy force-pushed the bq-reservation-cross-region branch from a0f4a2c to d5f98e2 Compare February 5, 2025 09:31
// to create a failover reservation or in update reservation calls to convert
// a non-failover reservation to a failover reservation(or vice versa).
// +kcc:proto:field=google.cloud.bigquery.reservation.v1.Reservation.secondary_location
SecondaryLocation *string `json:"secondaryLocation,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Turns out that API doesn't change the output returned to the PATCH requests

I left a comment regarding updateMask in the http PATCH request. I think it is related to the behavior you observed here. Let's fix the update logic in controller first.

@600lyy 600lyy force-pushed the bq-reservation-cross-region branch from 1e44066 to 74a97ee Compare February 7, 2025 09:01
…ng between failover and non-failover reservation
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