Merge pull request #4946 from a7i/remove-deploy-revision
fix: prune deployment revision annotation
This commit is contained in:
commit
e2b70282cf
|
@ -24,6 +24,7 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
storagevolume "k8s.io/component-helpers/storage/volume"
|
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"
|
||||||
"github.com/karmada-io/karmada/pkg/util/helper"
|
"github.com/karmada-io/karmada/pkg/util/helper"
|
||||||
|
@ -33,6 +34,7 @@ import (
|
||||||
type irrelevantFieldPruneFunc func(*unstructured.Unstructured) error
|
type irrelevantFieldPruneFunc func(*unstructured.Unstructured) error
|
||||||
|
|
||||||
var kindIrrelevantFieldPruners = map[string]irrelevantFieldPruneFunc{
|
var kindIrrelevantFieldPruners = map[string]irrelevantFieldPruneFunc{
|
||||||
|
util.DeploymentKind: removeDeploymentIrrelevantField,
|
||||||
util.JobKind: removeJobIrrelevantField,
|
util.JobKind: removeJobIrrelevantField,
|
||||||
util.SecretKind: removeSecretIrrelevantField,
|
util.SecretKind: removeSecretIrrelevantField,
|
||||||
util.ServiceAccountKind: removeServiceAccountIrrelevantField,
|
util.ServiceAccountKind: removeServiceAccountIrrelevantField,
|
||||||
|
@ -129,6 +131,14 @@ func removeGenerateSelectorOfJob(workload *unstructured.Unstructured) error {
|
||||||
return nil
|
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.
|
// RemoveJobTTLSeconds removes the '.spec.ttlSecondsAfterFinished' from a Job.
|
||||||
// The reason for removing it is that the Job propagated by Karmada probably be automatically deleted
|
// 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
|
// from member clusters(by 'ttl-after-finished' controller in member clusters). That will cause a conflict if
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
storagevolume "k8s.io/component-helpers/storage/volume"
|
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"
|
||||||
)
|
)
|
||||||
|
@ -239,6 +240,38 @@ func TestRemoveIrrelevantField(t *testing.T) {
|
||||||
{"metadata", "annotations", storagevolume.AnnSelectedNode},
|
{"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 {
|
for _, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue