Skip to content

Commit

Permalink
rename controll lable (#74)
Browse files Browse the repository at this point in the history
rename controll label
  • Loading branch information
shaofan-hs authored Aug 29, 2023
1 parent 19b2a68 commit 9977229
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 29 deletions.
2 changes: 0 additions & 2 deletions apis/apps/v1alpha1/well_known_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package v1alpha1
const (
ControlledByKusionStackLabelKey = "kusionstack.io/control"

ControlledByPodOpsLifecycle = "podopslifecycle.kusionstack.io/control" // indicate a pod is controlled by podopslifecycle

PodOperatingLabelPrefix = "operating.podopslifecycle.kusionstack.io" // indicate a pod is operating
PodOperationTypeLabelPrefix = "operation-type.podopslifecycle.kusionstack.io" // indicate the type of operation
PodOperationPermissionLabelPrefix = "operation-permission.podopslifecycle.kusionstack.io" // indicate the permission of operation
Expand Down
8 changes: 4 additions & 4 deletions pkg/controllers/collaset/predicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ type PodPredicate struct {

// Create returns true if the Create event should be processed
func (p *PodPredicate) Create(e event.CreateEvent) bool {
return utils.ControlledByPodOpsLifecycle(e.Object)
return utils.ControlledByKusionStack(e.Object)
}

// Delete returns true if the Delete event should be processed
func (p *PodPredicate) Delete(e event.DeleteEvent) bool {
return utils.ControlledByPodOpsLifecycle(e.Object)
return utils.ControlledByKusionStack(e.Object)
}

// Update returns true if the Update event should be processed
func (p *PodPredicate) Update(e event.UpdateEvent) bool {
return utils.ControlledByPodOpsLifecycle(e.ObjectNew) || utils.ControlledByPodOpsLifecycle(e.ObjectOld)
return utils.ControlledByKusionStack(e.ObjectNew) || utils.ControlledByKusionStack(e.ObjectOld)
}

// Generic returns true if the Generic event should be processed
func (p *PodPredicate) Generic(e event.GenericEvent) bool {
return utils.ControlledByPodOpsLifecycle(e.Object)
return utils.ControlledByKusionStack(e.Object)
}
2 changes: 1 addition & 1 deletion pkg/controllers/collaset/utils/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ func NewPodFrom(owner metav1.Object, ownerRef *metav1.OwnerReference, revision *
return nil, err
}

utils.ControlByPodOpsLifecycle(pod)
utils.ControllByKusionStack(pod)
return pod, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func AddToMgr(mgr manager.Manager, r reconcile.Reconciler) error {

err = c.Watch(&source.Kind{Type: &corev1.Pod{}}, &handler.EnqueueRequestForObject{}, &PodPredicate{
NeedOpsLifecycle: func(oldPod, newPod *corev1.Pod) bool {
return utils.ControlledByPodOpsLifecycle(newPod)
return utils.ControlledByKusionStack(newPod)
},
})
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ var _ = Describe("podopslifecycle controller", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
Labels: map[string]string{v1alpha1.ControlledByPodOpsLifecycle: "true"},
Labels: map[string]string{v1alpha1.ControlledByKusionStackLabelKey: "true"},
},
Spec: podSpec,
}
Expand All @@ -163,7 +163,7 @@ var _ = Describe("podopslifecycle controller", func() {
Name: "test",
Namespace: "default",
Labels: map[string]string{
v1alpha1.ControlledByPodOpsLifecycle: "true",
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperatingLabelPrefix, id): time,
fmt.Sprintf("%s/%s", v1alpha1.PodPrepareLabelPrefix, id): time,
},
Expand Down Expand Up @@ -192,7 +192,7 @@ var _ = Describe("podopslifecycle controller", func() {
Name: "test",
Namespace: "default",
Labels: map[string]string{
v1alpha1.ControlledByPodOpsLifecycle: "true",
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id): time,
fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, id): time,
},
Expand Down Expand Up @@ -220,7 +220,7 @@ var _ = Describe("podopslifecycle controller", func() {
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "default",
Labels: map[string]string{v1alpha1.ControlledByPodOpsLifecycle: "true"},
Labels: map[string]string{v1alpha1.ControlledByKusionStackLabelKey: "true"},
},
Spec: podSpec,
}
Expand All @@ -237,7 +237,7 @@ var _ = Describe("podopslifecycle controller", func() {
Expect(err).NotTo(HaveOccurred())

pod.ObjectMeta.Labels = map[string]string{
v1alpha1.ControlledByPodOpsLifecycle: "true",
v1alpha1.ControlledByKusionStackLabelKey: "true",
fmt.Sprintf("%s/%s", v1alpha1.PodOperateLabelPrefix, id): time,
fmt.Sprintf("%s/%s", v1alpha1.PodCompleteLabelPrefix, id): time,
}
Expand Down
7 changes: 2 additions & 5 deletions pkg/controllers/resourceconsist/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ package resourceconsist

const (
defaultMaxConcurrentReconciles = 5

controlledByResourceConsistAnnoKey = "resource-consist.kusionstack.io/control" // todo, replace to an unified label, like: kusionstack.io/control: "true"
expectedFinalizerAddedAnnoKey = "resource-consist.kusionstack.io/employees-expected-finalizer-added"

cleanFinalizerPrefix = "resource-consist.kusionstack.io/clean-"
expectedFinalizerAddedAnnoKey = "resource-consist.kusionstack.io/employees-expected-finalizer-added"
cleanFinalizerPrefix = "resource-consist.kusionstack.io/clean-"
)
10 changes: 5 additions & 5 deletions pkg/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ func DumpJSON(o interface{}) string {
return string(j)
}

func ControlledByPodOpsLifecycle(obj client.Object) bool {
func ControlledByKusionStack(obj client.Object) bool {
if obj == nil || obj.GetLabels() == nil {
return false
}
v, ok := obj.GetLabels()[v1alpha1.ControlledByPodOpsLifecycle]
v, ok := obj.GetLabels()[v1alpha1.ControlledByKusionStackLabelKey]
return ok && v == "true"
}

func ControlByPodOpsLifecycle(obj client.Object) {
func ControllByKusionStack(obj client.Object) {
if obj.GetLabels() == nil {
obj.SetLabels(map[string]string{})
}

if v, ok := obj.GetLabels()[v1alpha1.ControlledByPodOpsLifecycle]; !ok || v != "true" {
obj.GetLabels()[v1alpha1.ControlledByPodOpsLifecycle] = "true"
if v, ok := obj.GetLabels()[v1alpha1.ControlledByKusionStackLabelKey]; !ok || v != "true" {
obj.GetLabels()[v1alpha1.ControlledByKusionStackLabelKey] = "true"
}
}
2 changes: 1 addition & 1 deletion pkg/webhook/server/generic/pod/opslifecycle/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

func (lc *OpsLifecycle) Mutating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error {
if !utils.ControlledByPodOpsLifecycle(newPod) {
if !utils.ControlledByKusionStack(newPod) {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/server/generic/pod/opslifecycle/validating.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

func (lc *OpsLifecycle) Validating(ctx context.Context, c client.Client, oldPod, newPod *corev1.Pod, operation admissionv1.Operation) error {
if !utils.ControlledByPodOpsLifecycle(newPod) {
if !utils.ControlledByKusionStack(newPod) {
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/webhook/server/generic/pod/opslifecycle/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestValidating(t *testing.T) {
lifecycle := &OpsLifecycle{}
for _, v := range inputs {
if v.labels != nil {
v.labels[v1alpha1.ControlledByPodOpsLifecycle] = "true"
v.labels[v1alpha1.ControlledByKusionStackLabelKey] = "true"
}
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestMutating(t *testing.T) {
opslifecycle := &OpsLifecycle{}
for _, v := range inputs {
if v.oldPodLabels != nil {
v.oldPodLabels[v1alpha1.ControlledByPodOpsLifecycle] = "true"
v.oldPodLabels[v1alpha1.ControlledByKusionStackLabelKey] = "true"
}
oldPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -440,7 +440,7 @@ func TestMutating(t *testing.T) {
}

if v.newPodLabels != nil {
v.newPodLabels[v1alpha1.ControlledByPodOpsLifecycle] = "true"
v.newPodLabels[v1alpha1.ControlledByKusionStackLabelKey] = "true"
}
newPod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -470,7 +470,7 @@ func TestMutating(t *testing.T) {
}

if v.expectedLabels != nil {
v.expectedLabels[v1alpha1.ControlledByPodOpsLifecycle] = "true"
v.expectedLabels[v1alpha1.ControlledByKusionStackLabelKey] = "true"
}
assert.Equal(t, v.expectedLabels, newPod.Labels)
}
Expand Down

0 comments on commit 9977229

Please sign in to comment.