Skip to content
This repository was archived by the owner on Jun 26, 2024. It is now read-only.

Commit 3a2b276

Browse files
committed
spec: implement workload resource mapping
Implement support for ClusterWorkloadResourceMapping resources and most of their required semantics as dictated by the specification. The following are not implemented, and will be submitted in later patches: - validation on resource creation/modification - correct unbind behavior when the mapping changes Signed-off-by: Andy Sadler <[email protected]>
1 parent c9ab9c3 commit 3a2b276

27 files changed

+3091
-378
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright 2021 The Kubernetes Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
21+
// ClusterWorkloadResourceMappingTemplate defines the mapping for a specific version of an workload resource to a
22+
// logical PodTemplateSpec-like structure.
23+
type ClusterWorkloadResourceMappingTemplate struct {
24+
// Version is the version of the workload resource that this mapping is for.
25+
Version string `json:"version"`
26+
// Annotations is a Restricted JSONPath that references the annotations map within the workload resource. These
27+
// annotations must end up in the resulting Pod, and are generally not the workload resource's annotations.
28+
// Defaults to `.spec.template.metadata.annotations`.
29+
// +optional
30+
Annotations string `json:"annotations,omitempty"`
31+
// Containers is the collection of mappings to container-like fragments of the workload resource. Defaults to
32+
// mappings appropriate for a PodSpecable resource.
33+
// +optional
34+
Containers []ClusterWorkloadResourceMappingContainer `json:"containers,omitempty"`
35+
// Volumes is a Restricted JSONPath that references the slice of volumes within the workload resource. Defaults to
36+
// `.spec.template.spec.volumes`.
37+
// +optional
38+
Volumes string `json:"volumes,omitempty"`
39+
}
40+
41+
// ClusterWorkloadResourceMappingContainer defines the mapping for a specific fragment of an workload resource
42+
// to a Container-like structure.
43+
//
44+
// Each mapping defines exactly one path that may match multiple container-like fragments within the workload
45+
// resource. For each object matching the path the name, env and volumeMounts expressions are resolved to find those
46+
// structures.
47+
type ClusterWorkloadResourceMappingContainer struct {
48+
// Path is the JSONPath within the workload resource that matches an existing fragment that is container-like.
49+
Path string `json:"path"`
50+
// Name is a Restricted JSONPath that references the name of the container with the container-like workload resource
51+
// fragment. If not defined, container name filtering is ignored.
52+
// +optional
53+
Name string `json:"name,omitempty"`
54+
// Env is a Restricted JSONPath that references the slice of environment variables for the container with the
55+
// container-like workload resource fragment. The referenced location is created if it does not exist. Defaults
56+
// to `.envs`.
57+
// +optional
58+
Env string `json:"env,omitempty"`
59+
// VolumeMounts is a Restricted JSONPath that references the slice of volume mounts for the container with the
60+
// container-like workload resource fragment. The referenced location is created if it does not exist. Defaults
61+
// to `.volumeMounts`.
62+
// +optional
63+
VolumeMounts string `json:"volumeMounts,omitempty"`
64+
}
65+
66+
// ClusterWorkloadResourceMappingSpec defines the desired state of ClusterWorkloadResourceMapping
67+
type ClusterWorkloadResourceMappingSpec struct {
68+
// Versions is the collection of versions for a given resource, with mappings.
69+
Versions []ClusterWorkloadResourceMappingTemplate `json:"versions,omitempty"`
70+
}
71+
72+
// +kubebuilder:object:root=true
73+
// +kubebuilder:resource:scope=Cluster
74+
// +kubebuilder:storageversion
75+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
76+
77+
// ClusterWorkloadResourceMapping is the Schema for the clusterworkloadresourcemappings API
78+
type ClusterWorkloadResourceMapping struct {
79+
metav1.TypeMeta `json:",inline"`
80+
metav1.ObjectMeta `json:"metadata,omitempty"`
81+
82+
Spec ClusterWorkloadResourceMappingSpec `json:"spec,omitempty"`
83+
}
84+
85+
// +kubebuilder:object:root=true
86+
87+
// ClusterWorkloadResourceMappingList contains a list of ClusterWorkloadResourceMapping
88+
type ClusterWorkloadResourceMappingList struct {
89+
metav1.TypeMeta `json:",inline"`
90+
metav1.ListMeta `json:"metadata,omitempty"`
91+
92+
Items []ClusterWorkloadResourceMapping `json:"items"`
93+
}
94+
95+
var DefaultTemplate = ClusterWorkloadResourceMappingTemplate{
96+
Version: "*",
97+
Annotations: "",
98+
Volumes: ".spec.template.spec.volumes",
99+
Containers: []ClusterWorkloadResourceMappingContainer{
100+
{
101+
Path: ".spec.template.spec.containers[*]",
102+
Name: ".name",
103+
Env: ".env",
104+
VolumeMounts: ".volumeMounts",
105+
},
106+
{
107+
Path: ".spec.template.spec.initContainers[*]",
108+
Name: ".name",
109+
Env: ".env",
110+
VolumeMounts: ".volumeMounts",
111+
},
112+
},
113+
}

apis/spec/v1alpha3/groupversion_info.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ var (
3232

3333
GroupVersionKind = GroupVersion.WithKind("ServiceBinding")
3434

35+
WorkloadResourceMappingGroupVersionResource = GroupVersion.WithResource("clusterworkloadresourcemappings")
36+
37+
WorkloadResourceMappingGroupVersionKind = GroupVersion.WithKind("ClusterWorkloadResourceMapping")
38+
3539
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
3640
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
3741

apis/spec/v1alpha3/servicebinding_webhook.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ You may obtain a copy of the License at
99
1010
Unless required by applicable law or agreed to in writing, software
1111
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expr@wip
13-
ess or implied.
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1413
See the License for the specific language governing permissions and
1514
limitations under the License.
1615
*/

apis/spec/v1alpha3/zz_generated.deepcopy.go

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.8.0
7+
creationTimestamp: null
8+
name: clusterworkloadresourcemappings.servicebinding.io
9+
spec:
10+
group: servicebinding.io
11+
names:
12+
kind: ClusterWorkloadResourceMapping
13+
listKind: ClusterWorkloadResourceMappingList
14+
plural: clusterworkloadresourcemappings
15+
singular: clusterworkloadresourcemapping
16+
scope: Cluster
17+
versions:
18+
- additionalPrinterColumns:
19+
- jsonPath: .metadata.creationTimestamp
20+
name: Age
21+
type: date
22+
name: v1alpha3
23+
schema:
24+
openAPIV3Schema:
25+
description: ClusterWorkloadResourceMapping is the Schema for the clusterworkloadresourcemappings
26+
API
27+
properties:
28+
apiVersion:
29+
description: 'APIVersion defines the versioned schema of this representation
30+
of an object. Servers should convert recognized schemas to the latest
31+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
32+
type: string
33+
kind:
34+
description: 'Kind is a string value representing the REST resource this
35+
object represents. Servers may infer this from the endpoint the client
36+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
37+
type: string
38+
metadata:
39+
type: object
40+
spec:
41+
description: ClusterWorkloadResourceMappingSpec defines the desired state
42+
of ClusterWorkloadResourceMapping
43+
properties:
44+
versions:
45+
description: Versions is the collection of versions for a given resource,
46+
with mappings.
47+
items:
48+
description: ClusterWorkloadResourceMappingTemplate defines the
49+
mapping for a specific version of an workload resource to a logical
50+
PodTemplateSpec-like structure.
51+
properties:
52+
annotations:
53+
description: Annotations is a Restricted JSONPath that references
54+
the annotations map within the workload resource. These annotations
55+
must end up in the resulting Pod, and are generally not the
56+
workload resource's annotations. Defaults to `.spec.template.metadata.annotations`.
57+
type: string
58+
containers:
59+
description: Containers is the collection of mappings to container-like
60+
fragments of the workload resource. Defaults to mappings appropriate
61+
for a PodSpecable resource.
62+
items:
63+
description: "ClusterWorkloadResourceMappingContainer defines
64+
the mapping for a specific fragment of an workload resource
65+
to a Container-like structure. \n Each mapping defines exactly
66+
one path that may match multiple container-like fragments
67+
within the workload resource. For each object matching the
68+
path the name, env and volumeMounts expressions are resolved
69+
to find those structures."
70+
properties:
71+
env:
72+
description: Env is a Restricted JSONPath that references
73+
the slice of environment variables for the container
74+
with the container-like workload resource fragment.
75+
The referenced location is created if it does not exist.
76+
Defaults to `.envs`.
77+
type: string
78+
name:
79+
description: Name is a Restricted JSONPath that references
80+
the name of the container with the container-like workload
81+
resource fragment. If not defined, container name filtering
82+
is ignored.
83+
type: string
84+
path:
85+
description: Path is the JSONPath within the workload
86+
resource that matches an existing fragment that is container-like.
87+
type: string
88+
volumeMounts:
89+
description: VolumeMounts is a Restricted JSONPath that
90+
references the slice of volume mounts for the container
91+
with the container-like workload resource fragment.
92+
The referenced location is created if it does not exist.
93+
Defaults to `.volumeMounts`.
94+
type: string
95+
required:
96+
- path
97+
type: object
98+
type: array
99+
version:
100+
description: Version is the version of the workload resource
101+
that this mapping is for.
102+
type: string
103+
volumes:
104+
description: Volumes is a Restricted JSONPath that references
105+
the slice of volumes within the workload resource. Defaults
106+
to `.spec.template.spec.volumes`.
107+
type: string
108+
required:
109+
- version
110+
type: object
111+
type: array
112+
type: object
113+
type: object
114+
served: true
115+
storage: true
116+
subresources: {}
117+
status:
118+
acceptedNames:
119+
kind: ""
120+
plural: ""
121+
conditions: []
122+
storedVersions: []

config/crd/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ resources:
55
- bases/binding.operators.coreos.com_servicebindings.yaml
66
- bases/servicebinding.io_servicebindings.yaml
77
- bases/binding.operators.coreos.com_bindablekinds.yaml
8+
- bases/servicebinding.io_clusterworkloadresourcemappings.yaml
89
# +kubebuilder:scaffold:crdkustomizeresource
910

1011
patchesStrategicMerge:

0 commit comments

Comments
 (0)