Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prune deployment revision annotation #4946

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/resourceinterpreter/default/native/prune/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
storagevolume "k8s.io/component-helpers/storage/volume"
utildeployment "k8s.io/kubectl/pkg/util/deployment"

"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
Expand All @@ -33,6 +34,7 @@ import (
type irrelevantFieldPruneFunc func(*unstructured.Unstructured) error

var kindIrrelevantFieldPruners = map[string]irrelevantFieldPruneFunc{
util.DeploymentKind: removeDeploymentIrrelevantField,
util.JobKind: removeJobIrrelevantField,
util.SecretKind: removeSecretIrrelevantField,
util.ServiceAccountKind: removeServiceAccountIrrelevantField,
Expand Down Expand Up @@ -129,6 +131,14 @@ func removeGenerateSelectorOfJob(workload *unstructured.Unstructured) error {
return nil
}

func removeDeploymentIrrelevantField(workload *unstructured.Unstructured) error {
for _, annotation := range []string{utildeployment.RevisionAnnotation, utildeployment.RevisionHistoryAnnotation} {
unstructured.RemoveNestedField(workload.Object, "metadata", "annotations", annotation)
}

return nil
}

// RemoveJobTTLSeconds removes the '.spec.ttlSecondsAfterFinished' from a Job.
// The reason for removing it is that the Job propagated by Karmada probably be automatically deleted
// from member clusters(by 'ttl-after-finished' controller in member clusters). That will cause a conflict if
Expand Down
33 changes: 33 additions & 0 deletions pkg/resourceinterpreter/default/native/prune/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
storagevolume "k8s.io/component-helpers/storage/volume"
utildeployment "k8s.io/kubectl/pkg/util/deployment"

"github.com/karmada-io/karmada/pkg/util"
)
Expand Down Expand Up @@ -239,6 +240,38 @@ func TestRemoveIrrelevantField(t *testing.T) {
{"metadata", "annotations", storagevolume.AnnSelectedNode},
},
},
{
name: "removes deployment revision annotation",
workload: &unstructured.Unstructured{
Object: map[string]interface{}{
"kind": util.DeploymentKind,
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
utildeployment.RevisionAnnotation: 1,
},
},
},
},
unexpectedFields: []field{
{"metadata", "annotations", utildeployment.RevisionAnnotation},
},
},
{
name: "removes deployment revision history annotation",
workload: &unstructured.Unstructured{
Object: map[string]interface{}{
"kind": util.DeploymentKind,
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
utildeployment.RevisionHistoryAnnotation: "1,2",
},
},
},
},
unexpectedFields: []field{
{"metadata", "annotations", utildeployment.RevisionHistoryAnnotation},
},
},
}

for _, tt := range tests {
Expand Down