mirror of
https://github.com/clastix/kamaji.git
synced 2026-02-14 18:10:03 +00:00
feat: pod additional metadata
This commit is contained in:
@@ -141,8 +141,9 @@ type DeploymentSpec struct {
|
||||
// such as kube-apiserver, controller-manager, and scheduler. WARNING - This option
|
||||
// can override existing parameters and cause components to misbehave in unxpected ways.
|
||||
// Only modify if you know what you are doing.
|
||||
ExtraArgs *ControlPlaneExtraArgs `json:"extraArgs,omitempty"`
|
||||
AdditionalMetadata AdditionalMetadata `json:"additionalMetadata,omitempty"`
|
||||
ExtraArgs *ControlPlaneExtraArgs `json:"extraArgs,omitempty"`
|
||||
AdditionalMetadata AdditionalMetadata `json:"additionalMetadata,omitempty"`
|
||||
PodAdditionalMetadata AdditionalMetadata `json:"podAdditionalMetadata,omitempty"`
|
||||
// AdditionalInitContainers allows adding additional init containers to the Control Plane deployment.
|
||||
AdditionalInitContainers []corev1.Container `json:"additionalInitContainers,omitempty"`
|
||||
// AdditionalContainers allows adding additional containers to the Control Plane deployment.
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !ignore_autogenerated
|
||||
// +build !ignore_autogenerated
|
||||
|
||||
// Copyright 2022 Clastix Labs
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
@@ -578,6 +577,11 @@ func (in *DatastoreUsedSecret) DeepCopy() *DatastoreUsedSecret {
|
||||
func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
|
||||
*out = *in
|
||||
out.RegistrySettings = in.RegistrySettings
|
||||
if in.Replicas != nil {
|
||||
in, out := &in.Replicas, &out.Replicas
|
||||
*out = new(int32)
|
||||
**out = **in
|
||||
}
|
||||
if in.NodeSelector != nil {
|
||||
in, out := &in.NodeSelector, &out.NodeSelector
|
||||
*out = make(map[string]string, len(*in))
|
||||
@@ -616,6 +620,7 @@ func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) {
|
||||
(*in).DeepCopyInto(*out)
|
||||
}
|
||||
in.AdditionalMetadata.DeepCopyInto(&out.AdditionalMetadata)
|
||||
in.PodAdditionalMetadata.DeepCopyInto(&out.PodAdditionalMetadata)
|
||||
if in.AdditionalInitContainers != nil {
|
||||
in, out := &in.AdditionalInitContainers, &out.AdditionalInitContainers
|
||||
*out = make([]v1.Container, len(*in))
|
||||
|
||||
@@ -5677,6 +5677,20 @@ spec:
|
||||
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/
|
||||
type: object
|
||||
podAdditionalMetadata:
|
||||
description: AdditionalMetadata defines which additional metadata,
|
||||
such as labels and annotations, must be attached to the
|
||||
created resource.
|
||||
properties:
|
||||
annotations:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
registrySettings:
|
||||
default:
|
||||
apiServerImage: kube-apiserver
|
||||
|
||||
@@ -5991,6 +5991,20 @@ spec:
|
||||
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/
|
||||
type: object
|
||||
podAdditionalMetadata:
|
||||
description: AdditionalMetadata defines which additional metadata,
|
||||
such as labels and annotations, must be attached to the
|
||||
created resource.
|
||||
properties:
|
||||
annotations:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
registrySettings:
|
||||
default:
|
||||
apiServerImage: kube-apiserver
|
||||
|
||||
@@ -5967,6 +5967,18 @@ spec:
|
||||
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/
|
||||
type: object
|
||||
podAdditionalMetadata:
|
||||
description: AdditionalMetadata defines which additional metadata, such as labels and annotations, must be attached to the created resource.
|
||||
properties:
|
||||
annotations:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
labels:
|
||||
additionalProperties:
|
||||
type: string
|
||||
type: object
|
||||
type: object
|
||||
registrySettings:
|
||||
default:
|
||||
apiServerImage: kube-apiserver
|
||||
|
||||
@@ -1038,6 +1038,13 @@ Selector which must match a node's labels for the pod to be scheduled on that no
|
||||
More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/<br/>
|
||||
</td>
|
||||
<td>false</td>
|
||||
</tr><tr>
|
||||
<td><b><a href="#tenantcontrolplanespeccontrolplanedeploymentpodadditionalmetadata">podAdditionalMetadata</a></b></td>
|
||||
<td>object</td>
|
||||
<td>
|
||||
AdditionalMetadata defines which additional metadata, such as labels and annotations, must be attached to the created resource.<br/>
|
||||
</td>
|
||||
<td>false</td>
|
||||
</tr><tr>
|
||||
<td><b><a href="#tenantcontrolplanespeccontrolplanedeploymentregistrysettings">registrySettings</a></b></td>
|
||||
<td>object</td>
|
||||
@@ -12246,6 +12253,39 @@ Only modify if you know what you are doing.
|
||||
</table>
|
||||
|
||||
|
||||
### TenantControlPlane.spec.controlPlane.deployment.podAdditionalMetadata
|
||||
|
||||
|
||||
|
||||
AdditionalMetadata defines which additional metadata, such as labels and annotations, must be attached to the created resource.
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Description</th>
|
||||
<th>Required</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td><b>annotations</b></td>
|
||||
<td>map[string]string</td>
|
||||
<td>
|
||||
<br/>
|
||||
</td>
|
||||
<td>false</td>
|
||||
</tr><tr>
|
||||
<td><b>labels</b></td>
|
||||
<td>map[string]string</td>
|
||||
<td>
|
||||
<br/>
|
||||
</td>
|
||||
<td>false</td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
|
||||
|
||||
### TenantControlPlane.spec.controlPlane.deployment.registrySettings
|
||||
|
||||
|
||||
|
||||
78
e2e/tcp_pod_additional_metadata_test.go
Normal file
78
e2e/tcp_pod_additional_metadata_test.go
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2022 Clastix Labs
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
pointer "k8s.io/utils/ptr"
|
||||
|
||||
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
|
||||
)
|
||||
|
||||
var _ = Describe("Deploy a TenantControlPlane resource with additional pod metadata", func() {
|
||||
// Fill TenantControlPlane object
|
||||
tcp := &kamajiv1alpha1.TenantControlPlane{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "tcp-clusterip-additional-metadata",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: kamajiv1alpha1.TenantControlPlaneSpec{
|
||||
ControlPlane: kamajiv1alpha1.ControlPlane{
|
||||
Deployment: kamajiv1alpha1.DeploymentSpec{
|
||||
Replicas: pointer.To(int32(1)),
|
||||
PodAdditionalMetadata: kamajiv1alpha1.AdditionalMetadata{
|
||||
Labels: map[string]string{
|
||||
"hello-label": "world",
|
||||
"foo-label": "bar",
|
||||
},
|
||||
Annotations: map[string]string{
|
||||
"hello-ann": "world",
|
||||
"foo-ann": "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
Service: kamajiv1alpha1.ServiceSpec{
|
||||
ServiceType: "ClusterIP",
|
||||
},
|
||||
},
|
||||
NetworkProfile: kamajiv1alpha1.NetworkProfileSpec{
|
||||
Address: "172.18.0.2",
|
||||
},
|
||||
Kubernetes: kamajiv1alpha1.KubernetesSpec{
|
||||
Version: "v1.23.6",
|
||||
Kubelet: kamajiv1alpha1.KubeletSpec{
|
||||
CGroupFS: "cgroupfs",
|
||||
},
|
||||
AdmissionControllers: kamajiv1alpha1.AdmissionControllers{
|
||||
"LimitRanger",
|
||||
"ResourceQuota",
|
||||
},
|
||||
},
|
||||
Addons: kamajiv1alpha1.AddonsSpec{},
|
||||
},
|
||||
}
|
||||
|
||||
// Create a TenantControlPlane resource into the cluster
|
||||
JustBeforeEach(func() {
|
||||
Expect(k8sClient.Create(context.Background(), tcp)).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
// Delete the TenantControlPlane resource after test is finished
|
||||
JustAfterEach(func() {
|
||||
Expect(k8sClient.Delete(context.Background(), tcp)).Should(Succeed())
|
||||
})
|
||||
|
||||
// Check if TenantControlPlane resource has been created
|
||||
It("Should be Ready with expected additional metadata", func() {
|
||||
StatusMustEqualTo(tcp, kamajiv1alpha1.VersionReady)
|
||||
AllPodsLabelMustEqualTo(tcp, "hello-label", "world")
|
||||
AllPodsLabelMustEqualTo(tcp, "foo-label", "bar")
|
||||
AllPodsAnnotationMustEqualTo(tcp, "hello-ann", "world")
|
||||
AllPodsAnnotationMustEqualTo(tcp, "foo-ann", "bar")
|
||||
})
|
||||
})
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
|
||||
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
|
||||
)
|
||||
@@ -136,3 +137,41 @@ func StatusMustEqualTo(tcp *kamajiv1alpha1.TenantControlPlane, status kamajiv1al
|
||||
return *tcp.Status.Kubernetes.Version.Status
|
||||
}, 5*time.Minute, time.Second).Should(Equal(status))
|
||||
}
|
||||
|
||||
func AllPodsLabelMustEqualTo(tcp *kamajiv1alpha1.TenantControlPlane, label string, value string) {
|
||||
Eventually(func() bool {
|
||||
tcpPods := &corev1.PodList{}
|
||||
err := k8sClient.List(context.Background(), tcpPods, client.MatchingLabels{
|
||||
"kamaji.clastix.io/name": tcp.GetName(),
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, pod := range tcpPods.Items {
|
||||
if pod.Labels[label] != value {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}, 5*time.Minute, time.Second).Should(BeTrue())
|
||||
}
|
||||
|
||||
func AllPodsAnnotationMustEqualTo(tcp *kamajiv1alpha1.TenantControlPlane, annotation string, value string) {
|
||||
Eventually(func() bool {
|
||||
tcpPods := &corev1.PodList{}
|
||||
err := k8sClient.List(context.Background(), tcpPods, client.MatchingLabels{
|
||||
"kamaji.clastix.io/name": tcp.GetName(),
|
||||
})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, pod := range tcpPods.Items {
|
||||
if pod.Annotations[annotation] != value {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}, 5*time.Minute, time.Second).Should(BeTrue())
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ func (d Deployment) Build(ctx context.Context, deployment *appsv1.Deployment, te
|
||||
|
||||
d.setLabels(deployment, utilities.MergeMaps(utilities.KamajiLabels(tenantControlPlane.GetName(), "deployment"), tenantControlPlane.Spec.ControlPlane.Deployment.AdditionalMetadata.Labels))
|
||||
d.setAnnotations(deployment, utilities.MergeMaps(deployment.Annotations, tenantControlPlane.Spec.ControlPlane.Deployment.AdditionalMetadata.Annotations))
|
||||
d.setTemplateLabels(&deployment.Spec.Template, d.templateLabels(ctx, &tenantControlPlane))
|
||||
d.setTemplateLabels(&deployment.Spec.Template, utilities.MergeMaps(d.templateLabels(ctx, &tenantControlPlane), tenantControlPlane.Spec.ControlPlane.Deployment.PodAdditionalMetadata.Labels))
|
||||
d.setTemplateAnnotations(&deployment.Spec.Template, tenantControlPlane.Spec.ControlPlane.Deployment.PodAdditionalMetadata.Annotations)
|
||||
d.setNodeSelector(&deployment.Spec.Template.Spec, tenantControlPlane)
|
||||
d.setToleration(&deployment.Spec.Template.Spec, tenantControlPlane)
|
||||
d.setAffinity(&deployment.Spec.Template.Spec, tenantControlPlane)
|
||||
@@ -1001,6 +1002,10 @@ func (d Deployment) setTemplateLabels(template *corev1.PodTemplateSpec, labels m
|
||||
template.SetLabels(labels)
|
||||
}
|
||||
|
||||
func (d Deployment) setTemplateAnnotations(template *corev1.PodTemplateSpec, annotations map[string]string) {
|
||||
template.SetAnnotations(annotations)
|
||||
}
|
||||
|
||||
func (d Deployment) setLabels(resource *appsv1.Deployment, labels map[string]string) {
|
||||
resource.SetLabels(labels)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user