Skip to content

Commit 9e6f735

Browse files
committed
Remove implementation of SetNodeTemplate method
1 parent c239f90 commit 9e6f735

File tree

5 files changed

+34
-124
lines changed

5 files changed

+34
-124
lines changed

mockgcp/mockcompute/nodegroupsv1.go

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package mockcompute
1717
import (
1818
"context"
1919

20-
"google.golang.org/grpc/codes"
21-
"google.golang.org/grpc/status"
2220
"google.golang.org/protobuf/proto"
2321

2422
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects"
@@ -63,7 +61,7 @@ func (s *NodeGroupsV1) Insert(ctx context.Context, req *pb.InsertNodeGroupReques
6361
obj.Kind = PtrTo("compute#nodegroup")
6462

6563
if err := s.storage.Create(ctx, fqn, obj); err != nil {
66-
return nil, status.Errorf(codes.Internal, "error creating node group: %v", err)
64+
return nil, err
6765
}
6866

6967
return s.newLRO(ctx, name.Project.ID)
@@ -79,7 +77,7 @@ func (s *NodeGroupsV1) Patch(ctx context.Context, req *pb.PatchNodeGroupRequest)
7977
obj := &pb.NodeGroup{}
8078

8179
if err := s.storage.Update(ctx, fqn, obj); err != nil {
82-
return nil, status.Errorf(codes.Internal, "error updating node group: %v", err)
80+
return nil, err
8381
}
8482

8583
return s.newLRO(ctx, name.Project.ID)
@@ -101,43 +99,16 @@ func (s *NodeGroupsV1) Delete(ctx context.Context, req *pb.DeleteNodeGroupReques
10199
return s.newLRO(ctx, name.Project.ID)
102100
}
103101

104-
func (s *NodeGroupsV1) SetNodeTemplate(ctx context.Context, req *pb.SetNodeTemplateNodeGroupRequest) (*pb.Operation, error) {
105-
name, err := s.newNodeTemplateNodeGroupName(req.GetProject(), req.GetZone(), req.GetNodeGroup(), req.GetNodeGroupsSetNodeTemplateRequestResource().GetNodeTemplate())
106-
if err != nil {
107-
return nil, err
108-
}
109-
110-
fqn := name.String()
111-
112-
obj := &pb.NodeGroup{}
113-
if err := s.storage.Create(ctx, fqn, obj); err != nil {
114-
return nil, status.Errorf(codes.Internal, "error set node template for node group: %v", err)
115-
}
116-
117-
return s.newLRO(ctx, name.Project.ID)
118-
}
119-
120102
type nodeGroupName struct {
121103
Project *projects.ProjectData
122104
Zone string
123105
Name string
124106
}
125107

126-
type nodeTemplateNodeGroupName struct {
127-
Project *projects.ProjectData
128-
Zone string
129-
NodeGroupName string
130-
NodeTemplateName string
131-
}
132-
133108
func (n *nodeGroupName) String() string {
134109
return "projects/" + n.Project.ID + "/zones/" + n.Zone + "/nodeGroups/" + n.Name
135110
}
136111

137-
func (n *nodeTemplateNodeGroupName) String() string {
138-
return "projects/" + n.Project.ID + "/zones/" + n.Zone + "/nodeGroups/" + n.NodeGroupName + "/setNodeTemplate/" + n.NodeTemplateName
139-
}
140-
141112
// newNodeGroupName builds a normalized nodeGroupName from the constituent parts.
142113
// The expected form is `projects/{project}/zones/{zone}/nodeGroups/{nodeGroup}`.
143114
func (s *MockService) newNodeGroupName(project string, zone string, name string) (*nodeGroupName, error) {
@@ -152,19 +123,3 @@ func (s *MockService) newNodeGroupName(project string, zone string, name string)
152123
Name: name,
153124
}, nil
154125
}
155-
156-
// newNodeGroupName builds a normalized nodeGroupName from the constituent parts.
157-
// The expected form is `projects/{project}/zones/{zone}/nodeGroups/{nodeGroup}/setNodeTemplate/{nodeTemplate}`.
158-
func (s *MockService) newNodeTemplateNodeGroupName(project string, zone string, nodeGroupName string, nodeTemplateName string) (*nodeTemplateNodeGroupName, error) {
159-
projectObj, err := s.projects.GetProjectByID(project)
160-
if err != nil {
161-
return nil, err
162-
}
163-
164-
return &nodeTemplateNodeGroupName{
165-
Project: projectObj,
166-
Zone: zone,
167-
NodeGroupName: nodeGroupName,
168-
NodeTemplateName: nodeTemplateName,
169-
}, nil
170-
}

mockgcp/mockcompute/nodetemplatesv1.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919

2020
"github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/common/projects"
2121
pb "github.com/GoogleCloudPlatform/k8s-config-connector/mockgcp/generated/mockgcp/cloud/compute/v1"
22-
"google.golang.org/grpc/codes"
23-
"google.golang.org/grpc/status"
2422
"google.golang.org/protobuf/proto"
2523
)
2624

@@ -62,7 +60,7 @@ func (s *NodeTemplatesV1) Insert(ctx context.Context, req *pb.InsertNodeTemplate
6260
obj.Kind = PtrTo("compute#nodetemplate")
6361

6462
if err := s.storage.Create(ctx, fqn, obj); err != nil {
65-
return nil, status.Errorf(codes.Internal, "error creating node template: %v", err)
63+
return nil, err
6664
}
6765

6866
return s.newLRO(ctx, name.Project.ID)

pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computenodegroup/_http.log

Lines changed: 27 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Content-Type: application/json
2121
Grpc-Metadata-Content-Type: application/grpc
2222

2323
{
24-
"name": "operation-1707517787800-99b5547e-4961-44de-8ad6-76dbd62840d2",
25-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/operation-1707517787800-99b5547e-4961-44de-8ad6-76dbd62840d2",
24+
"name": "${operationId}",
25+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationId}",
2626
"status": "DONE",
2727
"warnings": []
2828
}
@@ -40,9 +40,9 @@ Grpc-Metadata-Content-Type: application/grpc
4040
{
4141
"accelerators": [],
4242
"cpuOvercommitType": "NONE",
43-
"creationTimestamp": "2024-02-09T22:29:47.8Z",
43+
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
4444
"disks": [],
45-
"id": "1707517787800358353",
45+
"id": "000000000000000000000",
4646
"kind": "compute#nodetemplate",
4747
"name": "computenodetemplate-${uniqueId}",
4848
"nodeAffinityLabels": {
@@ -54,7 +54,7 @@ Grpc-Metadata-Content-Type: application/grpc
5454
"memory": "any"
5555
},
5656
"region": "projects/${projectId}/global/regions/us-central1",
57-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/zones/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
57+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
5858
}
5959

6060
---
@@ -70,9 +70,9 @@ Grpc-Metadata-Content-Type: application/grpc
7070
{
7171
"accelerators": [],
7272
"cpuOvercommitType": "NONE",
73-
"creationTimestamp": "2024-02-09T22:29:47.8Z",
73+
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
7474
"disks": [],
75-
"id": "1707517787800358353",
75+
"id": "000000000000000000000",
7676
"kind": "compute#nodetemplate",
7777
"name": "computenodetemplate-${uniqueId}",
7878
"nodeAffinityLabels": {
@@ -84,7 +84,7 @@ Grpc-Metadata-Content-Type: application/grpc
8484
"memory": "any"
8585
},
8686
"region": "projects/${projectId}/global/regions/us-central1",
87-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/zones/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
87+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
8888
}
8989

9090
---
@@ -107,8 +107,8 @@ Content-Type: application/json
107107
Grpc-Metadata-Content-Type: application/grpc
108108

109109
{
110-
"name": "operation-1707517790516-8ef521f9-8418-4b12-8d5e-08641d5e023b",
111-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/operation-1707517790516-8ef521f9-8418-4b12-8d5e-08641d5e023b",
110+
"name": "${operationId}",
111+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationId}",
112112
"status": "DONE",
113113
"warnings": []
114114
}
@@ -124,9 +124,9 @@ Content-Type: application/json
124124
Grpc-Metadata-Content-Type: application/grpc
125125

126126
{
127-
"creationTimestamp": "2024-02-09T22:29:50.516Z",
127+
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
128128
"description": "A single sole-tenant node in the us-central1-b zone.",
129-
"id": "1707517790516025747",
129+
"id": "000000000000000000000",
130130
"kind": "compute#nodegroup",
131131
"maintenancePolicy": "DEFAULT",
132132
"name": "computenodegroup-${uniqueId}",
@@ -147,9 +147,9 @@ Content-Type: application/json
147147
Grpc-Metadata-Content-Type: application/grpc
148148

149149
{
150-
"creationTimestamp": "2024-02-09T22:29:50.516Z",
150+
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
151151
"description": "A single sole-tenant node in the us-central1-b zone.",
152-
"id": "1707517790516025747",
152+
"id": "000000000000000000000",
153153
"kind": "compute#nodegroup",
154154
"maintenancePolicy": "DEFAULT",
155155
"name": "computenodegroup-${uniqueId}",
@@ -161,27 +161,6 @@ Grpc-Metadata-Content-Type: application/grpc
161161

162162
---
163163

164-
POST https://compute.googleapis.com/compute/beta/projects/${projectId}/zones/us-central1-b/nodeGroups/computenodegroup-${uniqueId}/setNodeTemplate?alt=json
165-
Content-Type: application/json
166-
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/dev
167-
168-
{
169-
"nodeTemplate": "projects/${projectId}/regions/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
170-
}
171-
172-
200 OK
173-
Content-Type: application/json
174-
Grpc-Metadata-Content-Type: application/grpc
175-
176-
{
177-
"name": "operation-1707517790546-9fdf5874-7556-4113-8e3d-4294beada097",
178-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/operation-1707517790546-9fdf5874-7556-4113-8e3d-4294beada097",
179-
"status": "DONE",
180-
"warnings": []
181-
}
182-
183-
---
184-
185164
GET https://compute.googleapis.com/compute/beta/projects/${projectId}/zones/us-central1-b/nodeGroups/computenodegroup-${uniqueId}?alt=json
186165
Content-Type: application/json
187166
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/dev
@@ -191,9 +170,9 @@ Content-Type: application/json
191170
Grpc-Metadata-Content-Type: application/grpc
192171

193172
{
194-
"creationTimestamp": "2024-02-09T22:29:50.516Z",
173+
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
195174
"description": "A single sole-tenant node in the us-central1-b zone.",
196-
"id": "1707517790516025747",
175+
"id": "000000000000000000000",
197176
"kind": "compute#nodegroup",
198177
"maintenancePolicy": "DEFAULT",
199178
"name": "computenodegroup-${uniqueId}",
@@ -205,7 +184,7 @@ Grpc-Metadata-Content-Type: application/grpc
205184

206185
---
207186

208-
GET https://compute.googleapis.com/compute/beta/projects/${projectId}/zones/us-central1-b/nodeGroups/computenodegroup-${uniqueId}?alt=json
187+
DELETE https://compute.googleapis.com/compute/beta/projects/${projectId}/zones/us-central1-b/nodeGroups/computenodegroup-${uniqueId}?alt=json
209188
Content-Type: application/json
210189
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/dev
211190

@@ -214,16 +193,10 @@ Content-Type: application/json
214193
Grpc-Metadata-Content-Type: application/grpc
215194

216195
{
217-
"creationTimestamp": "2024-02-09T22:29:50.516Z",
218-
"description": "A single sole-tenant node in the us-central1-b zone.",
219-
"id": "1707517790516025747",
220-
"kind": "compute#nodegroup",
221-
"maintenancePolicy": "DEFAULT",
222-
"name": "computenodegroup-${uniqueId}",
223-
"nodeTemplate": "projects/${projectId}/regions/us-central1/nodeTemplates/computenodetemplate-${uniqueId}",
224-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/zones/us-central1-b/nodeGroups/computenodegroup-${uniqueId}",
225-
"size": 1,
226-
"zone": "projects/${projectId}/global/zones/us-central1-b"
196+
"name": "${operationId}",
197+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationId}",
198+
"status": "DONE",
199+
"warnings": []
227200
}
228201

229202
---
@@ -239,9 +212,9 @@ Grpc-Metadata-Content-Type: application/grpc
239212
{
240213
"accelerators": [],
241214
"cpuOvercommitType": "NONE",
242-
"creationTimestamp": "2024-02-09T22:29:47.8Z",
215+
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
243216
"disks": [],
244-
"id": "1707517787800358353",
217+
"id": "000000000000000000000",
245218
"kind": "compute#nodetemplate",
246219
"name": "computenodetemplate-${uniqueId}",
247220
"nodeAffinityLabels": {
@@ -253,24 +226,7 @@ Grpc-Metadata-Content-Type: application/grpc
253226
"memory": "any"
254227
},
255228
"region": "projects/${projectId}/global/regions/us-central1",
256-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/zones/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
257-
}
258-
259-
---
260-
261-
DELETE https://compute.googleapis.com/compute/beta/projects/${projectId}/zones/us-central1-b/nodeGroups/computenodegroup-${uniqueId}?alt=json
262-
Content-Type: application/json
263-
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/dev
264-
265-
200 OK
266-
Content-Type: application/json
267-
Grpc-Metadata-Content-Type: application/grpc
268-
269-
{
270-
"name": "operation-1707517791061-a4404c06-c824-496a-a553-34c86e5bf5f9",
271-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/operation-1707517791061-a4404c06-c824-496a-a553-34c86e5bf5f9",
272-
"status": "DONE",
273-
"warnings": []
229+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/regions/us-central1/nodeTemplates/computenodetemplate-${uniqueId}"
274230
}
275231

276232
---
@@ -284,8 +240,8 @@ Content-Type: application/json
284240
Grpc-Metadata-Content-Type: application/grpc
285241

286242
{
287-
"name": "operation-1707517791062-9560dc85-77fc-4782-95bc-ba3d24b95a53",
288-
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/operation-1707517791062-9560dc85-77fc-4782-95bc-ba3d24b95a53",
243+
"name": "${operationId}",
244+
"selfLink": "https://compute.googleapis.com/compute/v1/projects/${projectId}/global/operations/${operationId}",
289245
"status": "DONE",
290246
"warnings": []
291-
}
247+
}

pkg/test/resourcefixture/testdata/basic/compute/v1beta1/computenodetemplate/_http.log

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Grpc-Metadata-Content-Type: application/grpc
4545
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
4646
"description": "Node template for sole tenant nodes running in us-central1, with 96vCPUs and any amount of memory on any machine type.",
4747
"disks": [],
48-
"id": "1707779855744494373",
48+
"id": "000000000000000000000",
4949
"kind": "compute#nodetemplate",
5050
"name": "computenodetemplate-${uniqueId}",
5151
"nodeAffinityLabels": {
@@ -77,7 +77,7 @@ Grpc-Metadata-Content-Type: application/grpc
7777
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
7878
"description": "Node template for sole tenant nodes running in us-central1, with 96vCPUs and any amount of memory on any machine type.",
7979
"disks": [],
80-
"id": "1707779855744494373",
80+
"id": "000000000000000000000",
8181
"kind": "compute#nodetemplate",
8282
"name": "computenodetemplate-${uniqueId}",
8383
"nodeAffinityLabels": {
@@ -109,7 +109,7 @@ Grpc-Metadata-Content-Type: application/grpc
109109
"creationTimestamp": "2024-04-01T12:34:56.123456Z",
110110
"description": "Node template for sole tenant nodes running in us-central1, with 96vCPUs and any amount of memory on any machine type.",
111111
"disks": [],
112-
"id": "1707779855744494373",
112+
"id": "000000000000000000000",
113113
"kind": "compute#nodetemplate",
114114
"name": "computenodetemplate-${uniqueId}",
115115
"nodeAffinityLabels": {

tests/e2e/unified_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ func TestAllInSeries(t *testing.T) {
252252
})
253253
}
254254

255+
addReplacement("id", "000000000000000000000")
255256
addReplacement("uniqueId", "111111111111111111111")
256257
addReplacement("oauth2ClientId", "888888888888888888888")
257258

0 commit comments

Comments
 (0)