diff --git a/mockgcp/mockgkemulticloud/attachedcluster.go b/mockgcp/mockgkemulticloud/attachedcluster.go index 4c1be6bafaa..0dab0728258 100644 --- a/mockgcp/mockgkemulticloud/attachedcluster.go +++ b/mockgcp/mockgkemulticloud/attachedcluster.go @@ -17,6 +17,7 @@ package mockgkemulticloud import ( "context" "fmt" + "strings" "time" "google.golang.org/genproto/googleapis/longrunning" @@ -26,6 +27,7 @@ import ( "google.golang.org/protobuf/types/known/emptypb" "google.golang.org/protobuf/types/known/timestamppb" + "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/fields" pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/gkemulticloud/v1" ) @@ -45,7 +47,7 @@ func (s *GKEMulticloudV1) GetAttachedCluster(ctx context.Context, req *pb.GetAtt obj := &pb.AttachedCluster{} if err := s.storage.Get(ctx, fqn, obj); err != nil { if status.Code(err) == codes.NotFound { - return nil, status.Errorf(codes.NotFound, "Resource '%s' was not found", fqn) + return nil, status.Errorf(codes.NotFound, "cluster not found") } return nil, err } @@ -66,6 +68,28 @@ func (s *GKEMulticloudV1) CreateAttachedCluster(ctx context.Context, req *pb.Cre obj := proto.Clone(req.AttachedCluster).(*pb.AttachedCluster) obj.Name = fqn + if obj.GetBinaryAuthorization() == nil { + obj.BinaryAuthorization = &pb.BinaryAuthorization{ + EvaluationMode: pb.BinaryAuthorization_DISABLED, + } + } + if obj.GetMonitoringConfig() == nil { + obj.MonitoringConfig = &pb.MonitoringConfig{ + ManagedPrometheusConfig: &pb.ManagedPrometheusConfig{}, + } + } + obj.Fleet.Membership = obj.Fleet.Project + "/locations/global/memberships/" + req.AttachedClusterId + obj.CreateTime = timestamppb.New(now) + obj.UpdateTime = timestamppb.New(now) + obj.Etag = fields.ComputeWeakEtag(obj) + ver, err := trimPlatformVersion(req.GetAttachedCluster().GetPlatformVersion()) + if err != nil { + return nil, err + } + obj.KubernetesVersion = ver + obj.State = pb.AttachedCluster_RUNNING + obj.Uid = "111111111111111111111" + if err := s.storage.Create(ctx, fqn, obj); err != nil { return nil, err } @@ -130,6 +154,11 @@ func (s *GKEMulticloudV1) UpdateAttachedCluster(ctx context.Context, req *pb.Upd case "monitoring_config.managed_prometheus_config.enabled": obj.MonitoringConfig = req.GetAttachedCluster().GetMonitoringConfig() case "platformVersion": + ver, err := trimPlatformVersion(req.GetAttachedCluster().GetPlatformVersion()) + if err != nil { + return nil, err + } + obj.KubernetesVersion = ver obj.PlatformVersion = req.GetAttachedCluster().GetPlatformVersion() default: return nil, status.Errorf(codes.InvalidArgument, "update_mask path %q not valid", path) @@ -178,3 +207,11 @@ func (s *GKEMulticloudV1) DeleteAttachedCluster(ctx context.Context, req *pb.Del return &emptypb.Empty{}, nil }) } + +func trimPlatformVersion(platformVersion string) (string, error) { + tokens := strings.Split(platformVersion, ".") + if len(tokens) < 2 { + return "", status.Errorf(codes.InvalidArgument, "platform_version %q is not valid", platformVersion) + } + return tokens[0] + "." + tokens[1], nil +} diff --git a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_generated_object_containerattachedclusterbasic.golden.yaml b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_generated_object_containerattachedclusterbasic.golden.yaml index a89a831909c..21e01b4adf7 100644 --- a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_generated_object_containerattachedclusterbasic.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_generated_object_containerattachedclusterbasic.golden.yaml @@ -34,4 +34,9 @@ status: reason: UpToDate status: "True" type: Ready + createTime: "1970-01-01T00:00:00Z" + kubernetesVersion: "1.28" observedGeneration: 2 + state: RUNNING + uid: "12345678" + updateTime: "1970-01-01T00:00:00Z" diff --git a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_http.log b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_http.log index 6b4ca67bf03..3fa68d3eb13 100644 --- a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterbasic/_http.log @@ -247,7 +247,7 @@ X-Xss-Protection: 0 { "error": { "code": 404, - "message": "Resource 'projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127' was not found", + "message": "cluster not found", "status": "NOT_FOUND" } } @@ -322,18 +322,30 @@ X-Xss-Protection: 0 "name": "projects/${projectId}/locations/us-west1/operations/${operationID}", "response": { "@type": "type.googleapis.com/google.cloud.gkemulticloud.v1.AttachedCluster", + "binaryAuthorization": { + "evaluationMode": "DISABLED" + }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.27", "loggingConfig": {}, + "monitoringConfig": { + "managedPrometheusConfig": {} + }, "name": "projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127", "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, "platformVersion": "1.27.0-gke.2", - "state": "RUNNING" + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } } @@ -355,17 +367,30 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { + "binaryAuthorization": { + "evaluationMode": "DISABLED" + }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.27", "loggingConfig": {}, + "monitoringConfig": { + "managedPrometheusConfig": {} + }, "name": "projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127", "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, - "platformVersion": "1.27.0-gke.2" + "platformVersion": "1.27.0-gke.2", + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } --- @@ -375,13 +400,18 @@ Content-Type: application/json User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager { + "binaryAuthorization": { + "evaluationMode": "DISABLED" + }, "description": "Test attached cluster update", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, "loggingConfig": { "componentConfig": null }, + "monitoringConfig": {}, "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, @@ -438,17 +468,30 @@ X-Xss-Protection: 0 "name": "projects/${projectId}/locations/us-west1/operations/${operationID}", "response": { "@type": "type.googleapis.com/google.cloud.gkemulticloud.v1.AttachedCluster", + "binaryAuthorization": { + "evaluationMode": "DISABLED" + }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster update", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.28", "loggingConfig": {}, + "monitoringConfig": { + "managedPrometheusConfig": {} + }, "name": "projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127", "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, - "platformVersion": "1.28.0-gke.2" + "platformVersion": "1.28.0-gke.2", + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } } @@ -470,17 +513,30 @@ X-Frame-Options: SAMEORIGIN X-Xss-Protection: 0 { + "binaryAuthorization": { + "evaluationMode": "DISABLED" + }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster update", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.28", "loggingConfig": {}, + "monitoringConfig": { + "managedPrometheusConfig": {} + }, "name": "projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127", "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, - "platformVersion": "1.28.0-gke.2" + "platformVersion": "1.28.0-gke.2", + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } --- diff --git a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_generated_object_containerattachedclusterfull.golden.yaml b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_generated_object_containerattachedclusterfull.golden.yaml index 49ea4179dcd..1ff75d5eab8 100644 --- a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_generated_object_containerattachedclusterfull.golden.yaml +++ b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_generated_object_containerattachedclusterfull.golden.yaml @@ -52,4 +52,9 @@ status: reason: UpToDate status: "True" type: Ready + createTime: "1970-01-01T00:00:00Z" + kubernetesVersion: "1.28" observedGeneration: 2 + state: RUNNING + uid: "12345678" + updateTime: "1970-01-01T00:00:00Z" diff --git a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_http.log b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_http.log index 73b506b8a7f..997b28b37fb 100644 --- a/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/containerattached/v1beta1/containerattachedclusterfull/_http.log @@ -247,7 +247,7 @@ X-Xss-Protection: 0 { "error": { "code": 404, - "message": "Resource 'projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127' was not found", + "message": "cluster not found", "status": "NOT_FOUND" } } @@ -356,11 +356,15 @@ X-Xss-Protection: 0 "binaryAuthorization": { "evaluationMode": "PROJECT_SINGLETON_POLICY_ENFORCE" }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.27", "loggingConfig": { "componentConfig": { "enableComponents": [ @@ -368,12 +372,17 @@ X-Xss-Protection: 0 ] } }, + "monitoringConfig": { + "managedPrometheusConfig": {} + }, "name": "projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127", "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, "platformVersion": "1.27.0-gke.2", - "state": "RUNNING" + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } } @@ -409,11 +418,15 @@ X-Xss-Protection: 0 "binaryAuthorization": { "evaluationMode": "PROJECT_SINGLETON_POLICY_ENFORCE" }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.27", "loggingConfig": { "componentConfig": { "enableComponents": [ @@ -421,11 +434,17 @@ X-Xss-Protection: 0 ] } }, + "monitoringConfig": { + "managedPrometheusConfig": {} + }, "name": "projects/${projectId}/locations/us-west1/attachedClusters/kcc-attached-cluster-127", "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, - "platformVersion": "1.27.0-gke.2" + "platformVersion": "1.27.0-gke.2", + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } --- @@ -455,6 +474,7 @@ User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 t }, "description": "Test attached cluster update", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, "loggingConfig": { @@ -544,11 +564,15 @@ X-Xss-Protection: 0 "binaryAuthorization": { "evaluationMode": "DISABLED" }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster update", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.28", "loggingConfig": { "componentConfig": { "enableComponents": [ @@ -566,7 +590,10 @@ X-Xss-Protection: 0 "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, - "platformVersion": "1.28.0-gke.2" + "platformVersion": "1.28.0-gke.2", + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } } @@ -606,11 +633,15 @@ X-Xss-Protection: 0 "binaryAuthorization": { "evaluationMode": "DISABLED" }, + "createTime": "2024-04-01T12:34:56.123456Z", "description": "Test attached cluster update", "distribution": "eks", + "etag": "abcdef0123A=", "fleet": { + "membership": "projects/${projectNumber}/locations/global/memberships/kcc-attached-cluster-127", "project": "projects/${projectNumber}" }, + "kubernetesVersion": "1.28", "loggingConfig": { "componentConfig": { "enableComponents": [ @@ -628,7 +659,10 @@ X-Xss-Protection: 0 "oidcConfig": { "issuerUrl": "https://oidc.eks.us-west-2.amazonaws.com/id/A115FE1C770C2452C75219524036FC0F" }, - "platformVersion": "1.28.0-gke.2" + "platformVersion": "1.28.0-gke.2", + "state": "RUNNING", + "uid": "111111111111111111111", + "updateTime": "2024-04-01T12:34:56.123456Z" } ---