mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-06-19 03:39:32 -04:00
operator: use mainconstants
This commit is contained in:
parent
94694c6e06
commit
01e870c83a
4 changed files with 36 additions and 35 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
mainconstants "github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1"
|
updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/errors"
|
"k8s.io/apimachinery/pkg/api/errors"
|
||||||
|
@ -26,9 +27,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// NodeKubernetesComponentsReferenceAnnotationKey is the name of the annotation holding the reference to the ConfigMap listing all K8s components.
|
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey = "constellation.edgeless.systems/kubernetes-components"
|
|
||||||
|
|
||||||
joiningNodeNameKey = ".spec.name"
|
joiningNodeNameKey = ".spec.name"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -76,7 +74,7 @@ func (r *JoiningNodesReconciler) Reconcile(ctx context.Context, req ctrl.Request
|
||||||
if node.Annotations == nil {
|
if node.Annotations == nil {
|
||||||
node.Annotations = map[string]string{}
|
node.Annotations = map[string]string{}
|
||||||
}
|
}
|
||||||
node.Annotations[NodeKubernetesComponentsReferenceAnnotationKey] = joiningNode.Spec.ComponentsReference
|
node.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey] = joiningNode.Spec.ComponentsReference
|
||||||
return r.Update(ctx, &node)
|
return r.Update(ctx, &node)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
|
|
||||||
|
mainconstants "github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1"
|
updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ var _ = Describe("JoiningNode controller", func() {
|
||||||
By("annotating the node")
|
By("annotating the node")
|
||||||
Eventually(func() string {
|
Eventually(func() string {
|
||||||
_ = k8sClient.Get(ctx, types.NamespacedName{Name: nodeName1}, createdNode)
|
_ = k8sClient.Get(ctx, types.NamespacedName{Name: nodeName1}, createdNode)
|
||||||
return createdNode.Annotations[NodeKubernetesComponentsReferenceAnnotationKey]
|
return createdNode.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey]
|
||||||
}, timeout, interval).Should(Equal(ComponentsReference1))
|
}, timeout, interval).Should(Equal(ComponentsReference1))
|
||||||
|
|
||||||
By("deleting the joining node resource")
|
By("deleting the joining node resource")
|
||||||
|
@ -134,7 +135,7 @@ var _ = Describe("JoiningNode controller", func() {
|
||||||
By("annotating the node")
|
By("annotating the node")
|
||||||
Eventually(func() string {
|
Eventually(func() string {
|
||||||
_ = k8sClient.Get(ctx, types.NamespacedName{Name: createdNode.Name}, createdNode)
|
_ = k8sClient.Get(ctx, types.NamespacedName{Name: createdNode.Name}, createdNode)
|
||||||
return createdNode.Annotations[NodeKubernetesComponentsReferenceAnnotationKey]
|
return createdNode.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey]
|
||||||
}, timeout, interval).Should(Equal(ComponentsReference2))
|
}, timeout, interval).Should(Equal(ComponentsReference2))
|
||||||
|
|
||||||
By("deleting the joining node resource")
|
By("deleting the joining node resource")
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
mainconstants "github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
nodeutil "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/internal/node"
|
nodeutil "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/internal/node"
|
||||||
"github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/internal/patch"
|
"github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/internal/patch"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
@ -776,7 +777,7 @@ func groupNodes(nodes []corev1.Node, pendingNodes []updatev1alpha1.PendingNode,
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !strings.EqualFold(node.Annotations[nodeImageAnnotation], latestImageReference) ||
|
if !strings.EqualFold(node.Annotations[nodeImageAnnotation], latestImageReference) ||
|
||||||
!strings.EqualFold(node.Annotations[NodeKubernetesComponentsReferenceAnnotationKey], latestK8sComponentsReference) {
|
!strings.EqualFold(node.Annotations[mainconstants.NodeKubernetesComponentsHashAnnotationKey], latestK8sComponentsReference) {
|
||||||
if heir := node.Annotations[heirAnnotation]; heir != "" {
|
if heir := node.Annotations[heirAnnotation]; heir != "" {
|
||||||
groups.Donors = append(groups.Donors, node)
|
groups.Donors = append(groups.Donors, node)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
|
||||||
|
mainconstants "github.com/edgelesssys/constellation/v2/internal/constants"
|
||||||
updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1"
|
updatev1alpha1 "github.com/edgelesssys/constellation/v2/operators/constellation-node-operator/v2/api/v1alpha1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -608,9 +609,9 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "outdated",
|
Name: "outdated",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference,
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference,
|
||||||
nodeImageAnnotation: "old-image",
|
nodeImageAnnotation: "old-image",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -618,9 +619,9 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "outdated",
|
Name: "outdated",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: "old-ref",
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: "old-ref",
|
||||||
nodeImageAnnotation: latestImageReference,
|
nodeImageAnnotation: latestImageReference,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -630,9 +631,9 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "uptodate",
|
Name: "uptodate",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
nodeImageAnnotation: latestImageReference,
|
nodeImageAnnotation: latestImageReference,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference,
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -642,10 +643,10 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "donor",
|
Name: "donor",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
nodeImageAnnotation: "old-image",
|
nodeImageAnnotation: "old-image",
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference,
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference,
|
||||||
heirAnnotation: "heir",
|
heirAnnotation: "heir",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -653,10 +654,10 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "donor",
|
Name: "donor",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
nodeImageAnnotation: latestImageReference,
|
nodeImageAnnotation: latestImageReference,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: "old-ref",
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: "old-ref",
|
||||||
heirAnnotation: "heir",
|
heirAnnotation: "heir",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -666,10 +667,10 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "heir",
|
Name: "heir",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
nodeImageAnnotation: latestImageReference,
|
nodeImageAnnotation: latestImageReference,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference,
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference,
|
||||||
donorAnnotation: "donor",
|
donorAnnotation: "donor",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -679,10 +680,10 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "obsolete",
|
Name: "obsolete",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
nodeImageAnnotation: latestImageReference,
|
nodeImageAnnotation: latestImageReference,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference,
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference,
|
||||||
obsoleteAnnotation: "true",
|
obsoleteAnnotation: "true",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -693,9 +694,9 @@ func TestGroupNodes(t *testing.T) {
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "mint",
|
Name: "mint",
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
scalingGroupAnnotation: scalingGroup,
|
scalingGroupAnnotation: scalingGroup,
|
||||||
nodeImageAnnotation: latestImageReference,
|
nodeImageAnnotation: latestImageReference,
|
||||||
NodeKubernetesComponentsReferenceAnnotationKey: latestK8sComponentsReference,
|
mainconstants.NodeKubernetesComponentsHashAnnotationKey: latestK8sComponentsReference,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue