|
| 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 | +} |
0 commit comments