Skip to content

Commit eafe808

Browse files
committed
CORS-3842: Add API Updates for GCP Custom API Endpoints
** Add the Tech preview and No upgrade tags for the new feature GCP API Custom Endpoints. ** Add the ServiceEndpoint Structure that includes the api name and endpoint. ** Add the Service Endpoints to the GCP Spec and Status structs.
1 parent 913eae8 commit eafe808

File tree

31 files changed

+6050
-1
lines changed

31 files changed

+6050
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
2+
name: "Infrastructure"
3+
crdName: infrastructures.config.openshift.io
4+
featureGates:
5+
- GCPCustomAPIEndpoints
6+
tests:
7+
onCreate:
8+
- name: Should be able to create a minimal Infrastructure
9+
initial: |
10+
apiVersion: config.openshift.io/v1
11+
kind: Infrastructure
12+
spec: {} # No spec is required for a Infrastructure
13+
expected: |
14+
apiVersion: config.openshift.io/v1
15+
kind: Infrastructure
16+
spec: {}
17+
onUpdate:
18+
- name: Basic Service Endpoint
19+
initial: |
20+
apiVersion: config.openshift.io/v1
21+
kind: Infrastructure
22+
spec:
23+
platformSpec:
24+
type: GCP
25+
gcp: {}
26+
status:
27+
controlPlaneTopology: HighlyAvailable
28+
cpuPartitioning: None
29+
infrastructureTopology: HighlyAvailable
30+
platform: GCP
31+
platformStatus:
32+
type: GCP
33+
gcp:
34+
cloudLoadBalancerConfig:
35+
dnsType: PlatformDefault
36+
serviceEndpoints:
37+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com"}
38+
updated: |
39+
apiVersion: config.openshift.io/v1
40+
kind: Infrastructure
41+
spec:
42+
platformSpec:
43+
type: GCP
44+
gcp: {}
45+
status:
46+
controlPlaneTopology: HighlyAvailable
47+
cpuPartitioning: None
48+
infrastructureTopology: HighlyAvailable
49+
platform: GCP
50+
platformStatus:
51+
type: GCP
52+
gcp:
53+
cloudLoadBalancerConfig:
54+
dnsType: PlatformDefault
55+
serviceEndpoints:
56+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com"}
57+
expected: |
58+
apiVersion: config.openshift.io/v1
59+
kind: Infrastructure
60+
spec:
61+
platformSpec:
62+
type: GCP
63+
gcp: {}
64+
status:
65+
controlPlaneTopology: HighlyAvailable
66+
cpuPartitioning: None
67+
infrastructureTopology: HighlyAvailable
68+
platform: GCP
69+
platformStatus:
70+
type: GCP
71+
gcp:
72+
cloudLoadBalancerConfig:
73+
dnsType: PlatformDefault
74+
serviceEndpoints:
75+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com"}
76+
- name: Service Endpoint Same Name
77+
initial: |
78+
apiVersion: config.openshift.io/v1
79+
kind: Infrastructure
80+
spec:
81+
platformSpec:
82+
type: GCP
83+
gcp: {}
84+
updated: |
85+
apiVersion: config.openshift.io/v1
86+
kind: Infrastructure
87+
spec:
88+
platformSpec:
89+
type: GCP
90+
gcp: {}
91+
status:
92+
controlPlaneTopology: HighlyAvailable
93+
cpuPartitioning: None
94+
infrastructureTopology: HighlyAvailable
95+
platform: GCP
96+
platformStatus:
97+
type: GCP
98+
gcp:
99+
cloudLoadBalancerConfig:
100+
dnsType: PlatformDefault
101+
serviceEndpoints:
102+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com"}
103+
- {name: "Compute", url: "https://compute-myendpoint2.p.googleapis.com"}
104+
expectedStatusError: "status.platformStatus.gcp.serviceEndpoints: Invalid value: \"array\": only 1 endpoint override is permitted per GCP service name"
105+
- name: Service Endpoint Empty URL
106+
initial: |
107+
apiVersion: config.openshift.io/v1
108+
kind: Infrastructure
109+
spec:
110+
platformSpec:
111+
type: GCP
112+
gcp: {}
113+
updated: |
114+
apiVersion: config.openshift.io/v1
115+
kind: Infrastructure
116+
spec:
117+
platformSpec:
118+
type: GCP
119+
gcp: {}
120+
status:
121+
controlPlaneTopology: HighlyAvailable
122+
cpuPartitioning: None
123+
infrastructureTopology: HighlyAvailable
124+
platform: GCP
125+
platformStatus:
126+
type: GCP
127+
gcp:
128+
cloudLoadBalancerConfig:
129+
dnsType: PlatformDefault
130+
serviceEndpoints:
131+
- {name: "Compute", url: ""}
132+
expectedStatusError: "status.platformStatus.gcp.serviceEndpoints[0].url: Invalid value: \"string\": must be a valid URL"
133+
- name: Service Endpoint HTTP URL
134+
initial: |
135+
apiVersion: config.openshift.io/v1
136+
kind: Infrastructure
137+
spec:
138+
platformSpec:
139+
type: GCP
140+
gcp: {}
141+
updated: |
142+
apiVersion: config.openshift.io/v1
143+
kind: Infrastructure
144+
spec:
145+
platformSpec:
146+
type: GCP
147+
gcp: {}
148+
status:
149+
controlPlaneTopology: HighlyAvailable
150+
cpuPartitioning: None
151+
infrastructureTopology: HighlyAvailable
152+
platform: GCP
153+
platformStatus:
154+
type: GCP
155+
gcp:
156+
cloudLoadBalancerConfig:
157+
dnsType: PlatformDefault
158+
serviceEndpoints:
159+
- {name: "Compute", url: "http://compute-myendpoint1.p.googleapis.com"}
160+
expectedStatusError: "status.platformStatus.gcp.serviceEndpoints[0].url: Invalid value: \"string\": scheme must be https"
161+
- name: Service Endpoint URL Too Long
162+
initial: |
163+
apiVersion: config.openshift.io/v1
164+
kind: Infrastructure
165+
spec:
166+
platformSpec:
167+
type: GCP
168+
gcp: {}
169+
updated: |
170+
apiVersion: config.openshift.io/v1
171+
kind: Infrastructure
172+
spec:
173+
platformSpec:
174+
type: GCP
175+
gcp: {}
176+
status:
177+
controlPlaneTopology: HighlyAvailable
178+
cpuPartitioning: None
179+
infrastructureTopology: HighlyAvailable
180+
platform: GCP
181+
platformStatus:
182+
type: GCP
183+
gcp:
184+
cloudLoadBalancerConfig:
185+
dnsType: PlatformDefault
186+
serviceEndpoints:
187+
- {name: "Compute", url: "https://compute-myendpoint1-where-the-url-name-length-is-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-way-wayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy-too-long.p.googleapis.com"}
188+
expectedStatusError: "[status.platformStatus.gcp.serviceEndpoints[0].url: Too long: may not be more than 253 bytes, <nil>: Invalid value: \"null\": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation]"
189+
- name: Service Endpoint Bad Name
190+
initial: |
191+
apiVersion: config.openshift.io/v1
192+
kind: Infrastructure
193+
spec:
194+
platformSpec:
195+
type: GCP
196+
gcp: {}
197+
updated: |
198+
apiVersion: config.openshift.io/v1
199+
kind: Infrastructure
200+
spec:
201+
platformSpec:
202+
type: GCP
203+
gcp: {}
204+
status:
205+
controlPlaneTopology: HighlyAvailable
206+
cpuPartitioning: None
207+
infrastructureTopology: HighlyAvailable
208+
platform: GCP
209+
platformStatus:
210+
type: GCP
211+
gcp:
212+
cloudLoadBalancerConfig:
213+
dnsType: PlatformDefault
214+
serviceEndpoints:
215+
- {name: "UnknownService", url: "https://compute-myendpoint1.p.googleapis.com"}
216+
expectedStatusError: "[status.platformStatus.gcp.serviceEndpoints[0].name: Unsupported value: \"UnknownService\": supported values: \"Compute\", \"Container\", \"CloudResourceManager\", \"DNS\", \"File\", \"IAM\", \"ServiceUsage\", \"Storage\", \"TagManager\", <nil>: Invalid value: \"null\": some validation rules were not checked because the object was invalid; correct the existing errors to complete validation"
217+
- name: Service Endpoint End Slash
218+
initial: |
219+
apiVersion: config.openshift.io/v1
220+
kind: Infrastructure
221+
spec:
222+
platformSpec:
223+
type: GCP
224+
gcp: {}
225+
updated: |
226+
apiVersion: config.openshift.io/v1
227+
kind: Infrastructure
228+
spec:
229+
platformSpec:
230+
type: GCP
231+
gcp: {}
232+
status:
233+
controlPlaneTopology: HighlyAvailable
234+
cpuPartitioning: None
235+
infrastructureTopology: HighlyAvailable
236+
platform: GCP
237+
platformStatus:
238+
type: GCP
239+
gcp:
240+
cloudLoadBalancerConfig:
241+
dnsType: PlatformDefault
242+
serviceEndpoints:
243+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com/"}
244+
expected: |
245+
apiVersion: config.openshift.io/v1
246+
kind: Infrastructure
247+
spec:
248+
platformSpec:
249+
type: GCP
250+
gcp: {}
251+
status:
252+
controlPlaneTopology: HighlyAvailable
253+
cpuPartitioning: None
254+
infrastructureTopology: HighlyAvailable
255+
platform: GCP
256+
platformStatus:
257+
type: GCP
258+
gcp:
259+
cloudLoadBalancerConfig:
260+
dnsType: PlatformDefault
261+
serviceEndpoints:
262+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com/"}
263+
- name: Service Endpoint Bad Path
264+
initial: |
265+
apiVersion: config.openshift.io/v1
266+
kind: Infrastructure
267+
spec:
268+
platformSpec:
269+
type: GCP
270+
gcp: {}
271+
updated: |
272+
apiVersion: config.openshift.io/v1
273+
kind: Infrastructure
274+
spec:
275+
platformSpec:
276+
type: GCP
277+
gcp: {}
278+
status:
279+
controlPlaneTopology: HighlyAvailable
280+
cpuPartitioning: None
281+
infrastructureTopology: HighlyAvailable
282+
platform: GCP
283+
platformStatus:
284+
type: GCP
285+
gcp:
286+
cloudLoadBalancerConfig:
287+
dnsType: PlatformDefault
288+
serviceEndpoints:
289+
- {name: "Compute", url: "https://compute-myendpoint1.p.googleapis.com/bad"}
290+
expectedStatusError: "status.platformStatus.gcp.serviceEndpoints[0].url: Invalid value: \"string\": url must consist only of a scheme and domain. The url path must be empty."

config/v1/types_infrastructure.go

+76
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,69 @@ const (
624624
AzureStackCloud AzureCloudEnvironment = "AzureStackCloud"
625625
)
626626

627+
// GCPServiceEndpointName is the name of the GCP Service Endpoint.
628+
// +kubebuilder:validation:Enum=Compute;Container;CloudResourceManager;DNS;File;IAM;ServiceUsage;Storage;TagManager
629+
type GCPServiceEndpointName string
630+
631+
const (
632+
// GCPServiceEndpointNameCompute is the name used for the GCP Compute Service endpoint.
633+
GCPServiceEndpointNameCompute GCPServiceEndpointName = "Compute"
634+
635+
// GCPServiceEndpointNameContainer is the name used for the GCP Container Service endpoint.
636+
GCPServiceEndpointNameContainer GCPServiceEndpointName = "Container"
637+
638+
// GCPServiceEndpointNameCloudResource is the name used for the GCP Resource Manager Service endpoint.
639+
GCPServiceEndpointNameCloudResource GCPServiceEndpointName = "CloudResourceManager"
640+
641+
// GCPServiceEndpointNameDNS is the name used for the GCP DNS Service endpoint.
642+
GCPServiceEndpointNameDNS GCPServiceEndpointName = "DNS"
643+
644+
// GCPServiceEndpointNameFile is the name used for the GCP File Service endpoint.
645+
GCPServiceEndpointNameFile GCPServiceEndpointName = "File"
646+
647+
// GCPServiceEndpointNameIAM is the name used for the GCP IAM Service endpoint.
648+
GCPServiceEndpointNameIAM GCPServiceEndpointName = "IAM"
649+
650+
// GCPServiceEndpointNameServiceUsage is the name used for the GCP Service Usage Service endpoint.
651+
GCPServiceEndpointNameServiceUsage GCPServiceEndpointName = "ServiceUsage"
652+
653+
// GCPServiceEndpointNameStorage is the name used for the GCP Storage Service endpoint.
654+
GCPServiceEndpointNameStorage GCPServiceEndpointName = "Storage"
655+
656+
// GCPServiceEndpointNameTagManager is the name used for the GCP Tag Manager Service endpoint.
657+
GCPServiceEndpointNameTagManager GCPServiceEndpointName = "TagManager"
658+
)
659+
660+
// GCPServiceEndpoint store the configuration of a custom url to
661+
// override existing defaults of GCP Services.
662+
type GCPServiceEndpoint struct {
663+
// name is the name of the GCP service whose endpoint is being overridden.
664+
// This must be provided and cannot be empty.
665+
//
666+
// Allowed values are Compute, Container, CloudResourceManager, DNS, File, IAM, ServiceUsage,
667+
// Storage, and TagManager.
668+
//
669+
// As an example, when setting the name to Compute all requests made by the caller to the GCP Compute
670+
// Service will be directed to the endpoint specified in the url field.
671+
//
672+
// +required
673+
Name GCPServiceEndpointName `json:"name"`
674+
675+
// url is a fully qualified URI that overrides the default endpoint for a client using the GCP service specified
676+
// in the name field.
677+
// url is required, must use the scheme https, must not be more than 253 characters in length,
678+
// and must be a valid URL according to Go's net/url package (https://pkg.go.dev/net/url#URL)
679+
//
680+
// An example of a valid endpoint that overrides the Compute Service: "https://compute-myendpoint1.p.googleapis.com"
681+
//
682+
// +required
683+
// +kubebuilder:validation:MaxLength=253
684+
// +kubebuilder:validation:XValidation:rule="isURL(self)",message="must be a valid URL"
685+
// +kubebuilder:validation:XValidation:rule="isURL(self) ? (url(self).getScheme() == \"https\") : true",message="scheme must be https"
686+
// +kubebuilder:validation:XValidation:rule="url(self).getEscapedPath() == \"\" || url(self).getEscapedPath() == \"/\"",message="url must consist only of a scheme and domain. The url path must be empty."
687+
URL string `json:"url"`
688+
}
689+
627690
// GCPPlatformSpec holds the desired state of the Google Cloud Platform infrastructure provider.
628691
// This only includes fields that can be modified in the cluster.
629692
type GCPPlatformSpec struct{}
@@ -679,6 +742,19 @@ type GCPPlatformStatus struct {
679742
// +optional
680743
// +nullable
681744
CloudLoadBalancerConfig *CloudLoadBalancerConfig `json:"cloudLoadBalancerConfig,omitempty"`
745+
746+
// serviceEndpoints specifies endpoints that override the default endpoints
747+
// used when creating clients to interact with GCP services.
748+
// When not specified, the default endpoint for the GCP region will be used.
749+
// Only 1 endpoint override is permitted for each GCP service.
750+
// The maximum number of endpoint overrides allowed is 9.
751+
// +listType=map
752+
// +listMapKey=name
753+
// +kubebuilder:validation:MaxItems=9
754+
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x.name == y.name))",message="only 1 endpoint override is permitted per GCP service name"
755+
// +optional
756+
// +openshift:enable:FeatureGate=GCPCustomAPIEndpoints
757+
ServiceEndpoints []GCPServiceEndpoint `json:"serviceEndpoints,omitempty"`
682758
}
683759

684760
// GCPResourceLabel is a label to apply to GCP resources created for the cluster.

0 commit comments

Comments
 (0)