generated from kubernetes/kubernetes-template-project
/
provider_types.go
232 lines (190 loc) · 9.14 KB
/
provider_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
ctrlconfigv1 "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
)
const (
ProviderFinalizer = "provider.cluster.x-k8s.io"
ConfigMapVersionLabelName = "provider.cluster.x-k8s.io/version"
)
// ProviderSpec is the desired state of the Provider.
type ProviderSpec struct {
// Version indicates the provider version.
// +optional
Version string `json:"version,omitempty"`
// Manager defines the properties that can be enabled on the controller manager for the provider.
// +optional
Manager *ManagerSpec `json:"manager,omitempty"`
// Deployment defines the properties that can be enabled on the deployment for the provider.
// +optional
Deployment *DeploymentSpec `json:"deployment,omitempty"`
// SecretName is the name of the Secret providing the configuration
// variables for the current provider instance, like e.g. credentials.
// Such configurations will be used when creating or upgrading provider components.
// The contents of the secret will be treated as immutable. If changes need
// to be made, a new object can be created and the name should be updated.
// The contents should be in the form of key:value. This secret must be in
// the same namespace as the provider.
// +optional
SecretName string `json:"secretName,omitempty"`
// SecretNamespace is the namespace of the Secret providing the configuration variables. If not specified,
// the namespace of the provider will be used.
SecretNamespace string `json:"secretNamespace,omitempty"`
// FetchConfig determines how the operator will fetch the components and metadata for the provider.
// If nil, the operator will try to fetch components according to default
// embedded fetch configuration for the given kind and `ObjectMeta.Name`.
// For example, the infrastructure name `aws` will fetch artifacts from
// https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
// +optional
FetchConfig *FetchConfiguration `json:"fetchConfig,omitempty"`
// AdditionalManifests is reference to configmap that contains additional manifests that will be applied
// together with the provider components. The key for storing these manifests has to be `manifests`.
// The manifests are applied only once when a certain release is installed/upgraded. If namespace is not specified, the
// namespace of the provider will be used. There is no validation of the yaml content inside the configmap.
// +optional
AdditionalManifestsRef *ConfigmapReference `json:"additionalManifests,omitempty"`
}
// ConfigmapReference contains enough information to locate the configmap.
type ConfigmapReference struct {
// Name defines the name of the configmap.
Name string `json:"name"`
// Namespace defines the namespace of the configmap.
// +optional
Namespace string `json:"namespace,omitempty"`
}
// ManagerSpec defines the properties that can be enabled on the controller manager for the provider.
type ManagerSpec struct {
// ControllerManagerConfigurationSpec defines the desired state of GenericControllerManagerConfiguration.
ctrlconfigv1.ControllerManagerConfigurationSpec `json:",inline"`
// ProfilerAddress defines the bind address to expose the pprof profiler (e.g. localhost:6060).
// Default empty, meaning the profiler is disabled.
// Controller Manager flag is --profiler-address.
// +optional
ProfilerAddress string `json:"profilerAddress,omitempty"`
// MaxConcurrentReconciles is the maximum number of concurrent Reconciles
// which can be run.
// +optional
// +kubebuilder:validation:Minimum=1
MaxConcurrentReconciles int `json:"maxConcurrentReconciles,omitempty"`
// Verbosity set the logs verbosity. Defaults to 1.
// Controller Manager flag is --verbosity.
// +optional
// +kubebuilder:default=1
// +kubebuilder:validation:Minimum=0
Verbosity int `json:"verbosity,omitempty"`
// FeatureGates define provider specific feature flags that will be passed
// in as container args to the provider's controller manager.
// Controller Manager flag is --feature-gates.
FeatureGates map[string]bool `json:"featureGates,omitempty"`
}
// DeploymentSpec defines the properties that can be enabled on the Deployment for the provider.
type DeploymentSpec struct {
// Number of desired pods. This is a pointer to distinguish between explicit zero and not specified. Defaults to 1.
// +optional
// +kubebuilder:validation:Minimum=0
Replicas *int `json:"replicas,omitempty"`
// NodeSelector is a selector which must be true for the pod to fit on a node.
// Selector which must match a node's labels for the pod to be scheduled on that node.
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// If specified, the pod's tolerations.
// +optional
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
// If specified, the pod's scheduling constraints
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// List of containers specified in the Deployment
// +optional
Containers []ContainerSpec `json:"containers"`
// If specified, the pod's service account
// +optional
ServiceAccountName string `json:"serviceAccountName,omitempty"`
// List of image pull secrets specified in the Deployment
// +optional
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}
// ContainerSpec defines the properties available to override for each
// container in a provider deployment such as Image and Args to the container’s
// entrypoint.
type ContainerSpec struct {
// Name of the container. Cannot be updated.
Name string `json:"name"`
// Container Image Name
// +optional
Image *ImageMeta `json:"image,omitempty"`
// Args represents extra provider specific flags that are not encoded as fields in this API.
// Explicit controller manager properties defined in the `Provider.ManagerSpec`
// will have higher precedence than those defined in `ContainerSpec.Args`.
// For example, `ManagerSpec.SyncPeriod` will be used instead of the
// container arg `--sync-period` if both are defined.
// The same holds for `ManagerSpec.FeatureGates` and `--feature-gates`.
// +optional
Args map[string]string `json:"args,omitempty"`
// List of environment variables to set in the container.
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`
// Compute resources required by this container.
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// Command allows override container's entrypoint array.
Command []string `json:"command,omitempty"`
}
// ImageMeta allows to customize the image used.
type ImageMeta struct {
// Repository sets the container registry to pull images from.
// +optional
Repository string `json:"repository,omitempty"`
// Name allows to specify a name for the image.
// +optional
Name string `json:"name,omitempty"`
// Tag allows to specify a tag for the image.
// +optional
Tag string `json:"tag,omitempty"`
}
// FetchConfiguration determines the way to fetch the components and metadata for the provider.
type FetchConfiguration struct {
// URL to be used for fetching the provider’s components and metadata from a remote Github repository.
// For example, https://github.com/{owner}/{repository}/releases
// You must set `providerSpec.Version` field for operator to pick up
// desired version of the release from GitHub.
// +optional
URL string `json:"url,omitempty"`
// Selector to be used for fetching provider’s components and metadata from
// ConfigMaps stored inside the cluster. Each ConfigMap is expected to contain
// components and metadata for a specific version only.
// Note: the name of the ConfigMap should be set to the version or to override this
// add a label like the following: provider.cluster.x-k8s.io/version=v1.4.3
// +optional
Selector *metav1.LabelSelector `json:"selector,omitempty"`
}
// ProviderStatus defines the observed state of the Provider.
type ProviderStatus struct {
// Contract will contain the core provider contract that the provider is
// abiding by, like e.g. v1alpha4.
// +optional
Contract *string `json:"contract,omitempty"`
// Conditions define the current service state of the provider.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// InstalledVersion is the version of the provider that is installed.
// +optional
InstalledVersion *string `json:"installedVersion,omitempty"`
}