Skip to content

Commit

Permalink
improve labels and annotations definition (#1663)
Browse files Browse the repository at this point in the history
Signed-off-by: rambohe-ch <[email protected]>
  • Loading branch information
rambohe-ch authored Aug 18, 2023
1 parent de07563 commit efe75d5
Show file tree
Hide file tree
Showing 25 changed files with 95 additions and 205 deletions.
64 changes: 0 additions & 64 deletions pkg/apis/apps/v1alpha1/well_known_labels_annotations.go

This file was deleted.

2 changes: 0 additions & 2 deletions pkg/apis/apps/v1beta1/nodepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type NodePoolType string
const (
Edge NodePoolType = "Edge"
Cloud NodePoolType = "Cloud"

NodePoolTypeLabelKey = "openyurt.io/node-pool-type"
)

// NodePoolSpec defines the desired state of NodePool
Expand Down
29 changes: 11 additions & 18 deletions pkg/apis/apps/well_known_labels_annotations.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
/*
Copyright 2023 The OpenYurt Authors.
Copyright 2021 The OpenYurt 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
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.
@CHANGELOG
OpenYurt Authors:
change some const value
*/

package apps

// YurtAppSet & YurtAppDaemon related labels and annotations
const (
// ControllerRevisionHashLabelKey is used to record the controller revision of current resource.
ControllerRevisionHashLabelKey = "apps.openyurt.io/controller-revision-hash"

// PoolNameLabelKey is used to record the name of current pool.
PoolNameLabelKey = "apps.openyurt.io/pool-name"

// SpecifiedDeleteKey indicates this object should be deleted, and the value could be the deletion option.
SpecifiedDeleteKey = "apps.openyurt.io/specified-delete"

// AnnotationPatchKey indicates the patch for every sub pool
AnnotationPatchKey = "apps.openyurt.io/patch"

AnnotationRefNodePool = "apps.openyurt.io/ref-nodepool"
)

// NodePool related labels and annotations
const (
NodePoolTypeLabelKey = "openyurt.io/node-pool-type"

// LabelDesiredNodePool indicates which nodepool the node want to join
LabelDesiredNodePool = "apps.openyurt.io/desired-nodepool"

// LabelCurrentNodePool indicates which nodepool the node is currently
// belonging to
LabelCurrentNodePool = "apps.openyurt.io/nodepool"

AnnotationPrevAttrs = "nodepool.openyurt.io/previous-attributes"

AnnotationPrevAttrs = "nodepool.openyurt.io/previous-attributes"
NodePoolLabel = "apps.openyurt.io/nodepool"
NodePoolTypeLabel = "nodepool.openyurt.io/type"
NodePoolHostNetworkLabel = "nodepool.openyurt.io/hostnetwork"

NodePoolChangedEvent = "NodePoolChanged"
NodePoolChangedEvent = "NodePoolChanged"
)
50 changes: 0 additions & 50 deletions pkg/util/json.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/yurthub/filter/nodeportisolation/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestFilter(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Annotations: map[string]string{
apps.LabelDesiredNodePool: nodePoolName,
apps.NodePoolLabel: nodePoolName,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

appconfig "github.com/openyurtio/openyurt/cmd/yurt-manager/app/config"
"github.com/openyurtio/openyurt/pkg/apis/apps"
appsv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
iotv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha1"
iotv1alpha2 "github.com/openyurtio/openyurt/pkg/apis/iot/v1alpha2"
Expand Down Expand Up @@ -443,7 +444,7 @@ func (r *ReconcilePlatformAdmin) reconcileComponent(ctx context.Context, platfor
}
pool.NodeSelectorTerm.MatchExpressions = append(pool.NodeSelectorTerm.MatchExpressions,
corev1.NodeSelectorRequirement{
Key: appsv1alpha1.LabelCurrentNodePool,
Key: apps.NodePoolLabel,
Operator: corev1.NodeSelectorOpIn,
Values: []string{platformAdmin.Spec.PoolName},
})
Expand Down Expand Up @@ -561,7 +562,7 @@ func (r *ReconcilePlatformAdmin) handleYurtAppSet(ctx context.Context, platformA
}
pool.NodeSelectorTerm.MatchExpressions = append(pool.NodeSelectorTerm.MatchExpressions,
corev1.NodeSelectorRequirement{
Key: appsv1alpha1.LabelCurrentNodePool,
Key: apps.NodePoolLabel,
Operator: corev1.NodeSelectorOpIn,
Values: []string{platformAdmin.Spec.PoolName},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/event"

"github.com/openyurtio/openyurt/pkg/apis/apps"
appsv1alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
)

Expand Down Expand Up @@ -91,7 +92,7 @@ func TestCreate(t *testing.T) {
Namespace: "kube-system",
Name: "kube-proxy",
Annotations: map[string]string{
appsv1alpha1.AnnotationRefNodePool: "a",
apps.AnnotationRefNodePool: "a",
},
},
Spec: v1.PodSpec{},
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestUpdate(t *testing.T) {
Namespace: "kube-system",
Name: "kube-proxy",
Annotations: map[string]string{
appsv1alpha1.AnnotationRefNodePool: "a",
apps.AnnotationRefNodePool: "a",
},
},
Spec: v1.PodSpec{},
Expand All @@ -154,7 +155,7 @@ func TestUpdate(t *testing.T) {
Namespace: "kube-system",
Name: "kube-proxy",
Annotations: map[string]string{
appsv1alpha1.AnnotationRefNodePool: "a",
apps.AnnotationRefNodePool: "a",
},
},
Spec: v1.PodSpec{},
Expand Down Expand Up @@ -206,7 +207,7 @@ func TestDelete(t *testing.T) {
Namespace: "kube-system",
Name: "kube-proxy",
Annotations: map[string]string{
appsv1alpha1.AnnotationRefNodePool: "a",
apps.AnnotationRefNodePool: "a",
},
},
Spec: v1.PodSpec{},
Expand Down Expand Up @@ -260,7 +261,7 @@ func TestGeneric(t *testing.T) {
Namespace: "kube-system",
Name: "kube-proxy",
Annotations: map[string]string{
appsv1alpha1.AnnotationRefNodePool: "a",
apps.AnnotationRefNodePool: "a",
},
},
Spec: v1.PodSpec{},
Expand Down
3 changes: 2 additions & 1 deletion pkg/yurtmanager/controller/yurtappdaemon/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/client-go/tools/record"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

yurtapps "github.com/openyurtio/openyurt/pkg/apis/apps"
alpha1 "github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
)

Expand Down Expand Up @@ -81,7 +82,7 @@ func TestNewRevision(t *testing.T) {
},
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
alpha1.PoolNameLabelKey: "a",
yurtapps.PoolNameLabelKey: "a",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/openyurtio/openyurt/pkg/apis/apps"
"github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
"github.com/openyurtio/openyurt/pkg/yurtmanager/controller/util/refmanager"
)
Expand Down Expand Up @@ -67,22 +68,22 @@ func (d *DeploymentControllor) applyTemplate(scheme *runtime.Scheme, yad *v1alph
for k, v := range yad.Spec.Selector.MatchLabels {
set.Labels[k] = v
}
set.Labels[v1alpha1.ControllerRevisionHashLabelKey] = revision
set.Labels[v1alpha1.PoolNameLabelKey] = nodepool.GetName()
set.Labels[apps.ControllerRevisionHashLabelKey] = revision
set.Labels[apps.PoolNameLabelKey] = nodepool.GetName()

if set.Annotations == nil {
set.Annotations = map[string]string{}
}
for k, v := range yad.Spec.WorkloadTemplate.DeploymentTemplate.Annotations {
set.Annotations[k] = v
}
set.Annotations[v1alpha1.AnnotationRefNodePool] = nodepool.GetName()
set.Annotations[apps.AnnotationRefNodePool] = nodepool.GetName()

set.Namespace = yad.GetNamespace()
set.GenerateName = getWorkloadPrefix(yad.GetName(), nodepool.GetName())

set.Spec = *yad.Spec.WorkloadTemplate.DeploymentTemplate.Spec.DeepCopy()
set.Spec.Selector.MatchLabels[v1alpha1.PoolNameLabelKey] = nodepool.GetName()
set.Spec.Selector.MatchLabels[apps.PoolNameLabelKey] = nodepool.GetName()

// set RequiredDuringSchedulingIgnoredDuringExecution nil
if set.Spec.Template.Spec.Affinity != nil && set.Spec.Template.Spec.Affinity.NodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution != nil {
Expand All @@ -92,8 +93,8 @@ func (d *DeploymentControllor) applyTemplate(scheme *runtime.Scheme, yad *v1alph
if set.Spec.Template.Labels == nil {
set.Spec.Template.Labels = map[string]string{}
}
set.Spec.Template.Labels[v1alpha1.PoolNameLabelKey] = nodepool.GetName()
set.Spec.Template.Labels[v1alpha1.ControllerRevisionHashLabelKey] = revision
set.Spec.Template.Labels[apps.PoolNameLabelKey] = nodepool.GetName()
set.Spec.Template.Labels[apps.ControllerRevisionHashLabelKey] = revision

// use nodeSelector
set.Spec.Template.Spec.NodeSelector = CreateNodeSelectorByNodepoolName(nodepool.GetName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclint "sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/openyurtio/openyurt/pkg/apis/apps"
"github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
)

Expand Down Expand Up @@ -129,7 +130,7 @@ func TestApplyTemplate(t *testing.T) {
},
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
v1alpha1.PoolNameLabelKey: "a",
apps.PoolNameLabelKey: "a",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/validation"

"github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
"github.com/openyurtio/openyurt/pkg/apis/apps"
)

func getWorkloadPrefix(controllerName, nodepoolName string) string {
Expand All @@ -35,7 +35,7 @@ func getWorkloadPrefix(controllerName, nodepoolName string) string {

func CreateNodeSelectorByNodepoolName(nodepool string) map[string]string {
return map[string]string{
v1alpha1.LabelCurrentNodePool: nodepool,
apps.NodePoolLabel: nodepool,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

corev1 "k8s.io/api/core/v1"

"github.com/openyurtio/openyurt/pkg/apis/apps/v1alpha1"
"github.com/openyurtio/openyurt/pkg/apis/apps"
)

const (
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestCreateNodeSelectorByNodepoolName(t *testing.T) {
"normal",
"a",
map[string]string{
v1alpha1.LabelCurrentNodePool: "a",
apps.NodePoolLabel: "a",
},
},
}
Expand Down
Loading

0 comments on commit efe75d5

Please sign in to comment.