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

enh: support direct updates #2335

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mockgcp/mockdataform/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package mockdataform

import (
"context"
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -87,6 +88,10 @@ func (r *RepositoryV1Beta1) UpdateRepository(ctx context.Context, request *pb.Up
updateMask := request.GetUpdateMask()
for _, path := range updateMask.Paths {
switch path {
case "gitRemoteSettings":
obj.GitRemoteSettings = request.GetRepository().GetGitRemoteSettings()
case "workspaceCompilationOverrides":
obj.WorkspaceCompilationOverrides = request.GetRepository().GetWorkspaceCompilationOverrides()
default:
return nil, status.Errorf(codes.InvalidArgument, "field %q is not yet handled in mock", path)
}
Expand All @@ -96,6 +101,7 @@ func (r *RepositoryV1Beta1) UpdateRepository(ctx context.Context, request *pb.Up
return nil, err
}

fmt.Println("todo acpana did it")
return obj, nil
}
func (r *RepositoryV1Beta1) DeleteRepository(ctx context.Context, request *pb.DeleteRepositoryRequest) (*empty.Empty, error) {
Expand Down
14 changes: 13 additions & 1 deletion pkg/controller/direct/dataform/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package dataform
import (
"context"
"fmt"
"reflect"

krm "github.com/GoogleCloudPlatform/k8s-config-connector/apis/dataform/v1alpha1"
refs "github.com/GoogleCloudPlatform/k8s-config-connector/apis/refs/v1beta1"
Expand Down Expand Up @@ -188,7 +189,17 @@ func (a *Adapter) Create(ctx context.Context, u *unstructured.Unstructured) erro
func (a *Adapter) Update(ctx context.Context, u *unstructured.Unstructured) error {

updateMask := &fieldmaskpb.FieldMask{}
// TODO(acpana): handle updates

if a.desired.Spec.GitRemoteSettings != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Somewhere (maybe in an open PR) we have a helper to compute these, assuming we want the top-level fields.

Not a blocker

if !reflect.DeepEqual(a.desired.Spec.GitRemoteSettings, a.actual.GitRemoteSettings) {
updateMask.Paths = append(updateMask.Paths, "git_remote_settings")
}
}
if a.desired.Spec.WorkspaceCompilationOverrides != nil {
if !reflect.DeepEqual(a.desired.Spec.WorkspaceCompilationOverrides, a.actual.WorkspaceCompilationOverrides) {
updateMask.Paths = append(updateMask.Paths, "workspace_compilation_overrides")
}
}

desired := a.desired.DeepCopy()
mapCtx := &direct.MapContext{}
Expand All @@ -197,6 +208,7 @@ func (a *Adapter) Update(ctx context.Context, u *unstructured.Unstructured) erro
return fmt.Errorf("converting DataformRepository spec to api: %w", mapCtx.Err())
}

resource.Name = a.fullyQualifiedName()
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 think this could be part of the controller template

req := &dataformpb.UpdateRepositoryRequest{UpdateMask: updateMask, Repository: resource}
_, err := a.gcpClient.UpdateRepository(ctx, req)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
finalizers:
- cnrm.cloud.google.com/finalizer
- cnrm.cloud.google.com/deletion-defender
generation: 1
generation: 2
labels:
cnrm-test: "true"
name: dataformrepository-${uniqueId}
Expand All @@ -15,11 +15,15 @@ spec:
projectRef:
external: ${projectId}
region: us-west2
workspaceCompilationOverrides:
defaultDatabase: database
schemaSuffix: _suffix
tablePrefix: prefix_
status:
conditions:
- lastTransitionTime: "1970-01-01T00:00:00Z"
message: The resource is up to date
reason: UpToDate
status: "True"
type: Ready
observedGeneration: 1
observedGeneration: 2
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,65 @@ Grpc-Metadata-Content-Type: application/grpc

---

PATCH https://dataform.googleapis.com/v1beta1/projects/${projectId}/locations/us-west2/repositories/dataformrepository-${uniqueId}?%24alt=json%3Benum-encoding%3Dint&updateMask=workspaceCompilationOverrides
Content-Type: application/json
x-goog-request-params: repository.name=projects%2F${projectId}%2Flocations%2Fus-west2%2Frepositories%2Fdataformrepository-${uniqueId}

{
"name": "projects/${projectId}/locations/us-west2/repositories/dataformrepository-${uniqueId}",
"workspaceCompilationOverrides": {
"defaultDatabase": "database",
"schemaSuffix": "_suffix",
"tablePrefix": "prefix_"
}
}

200 OK
Content-Type: application/json
Grpc-Metadata-Content-Type: application/grpc

{
"displayName": "",
"gitRemoteSettings": null,
"labels": {},
"name": "projects/${projectId}/locations/us-west2/repositories/dataformrepository-${uniqueId}",
"npmrcEnvironmentVariablesSecretVersion": "",
"serviceAccount": "",
"setAuthenticatedUserAdmin": false,
"workspaceCompilationOverrides": {
"defaultDatabase": "database",
"schemaSuffix": "_suffix",
"tablePrefix": "prefix_"
}
}

---

GET https://dataform.googleapis.com/v1beta1/projects/${projectId}/locations/us-west2/repositories/dataformrepository-${uniqueId}?%24alt=json%3Benum-encoding%3Dint
Content-Type: application/json
x-goog-request-params: name=projects%2F${projectId}%2Flocations%2Fus-west2%2Frepositories%2Fdataformrepository-${uniqueId}

200 OK
Content-Type: application/json
Grpc-Metadata-Content-Type: application/grpc

{
"displayName": "",
"gitRemoteSettings": null,
"labels": {},
"name": "projects/${projectId}/locations/us-west2/repositories/dataformrepository-${uniqueId}",
"npmrcEnvironmentVariablesSecretVersion": "",
"serviceAccount": "",
"setAuthenticatedUserAdmin": false,
"workspaceCompilationOverrides": {
"defaultDatabase": "database",
"schemaSuffix": "_suffix",
"tablePrefix": "prefix_"
}
}

---

DELETE https://dataform.googleapis.com/v1beta1/projects/${projectId}/locations/us-west2/repositories/dataformrepository-${uniqueId}?%24alt=json%3Benum-encoding%3Dint
Content-Type: application/json
x-goog-request-params: name=projects%2F${projectId}%2Flocations%2Fus-west2%2Frepositories%2Fdataformrepository-${uniqueId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ metadata:
spec:
projectRef:
external: ${projectId}
region: us-west2
region: us-west2
acpana marked this conversation as resolved.
Show resolved Hide resolved
workspaceCompilationOverrides:
defaultDatabase: "database"
schemaSuffix: "_suffix"
tablePrefix: "prefix_"
Loading