From fcf68ba7a759c852522cd50fd01c49dc96ca3228 Mon Sep 17 00:00:00 2001 From: Michail Kargakis Date: Fri, 21 Apr 2017 16:47:32 +0200 Subject: [PATCH] Remove obsolete deployment helpers Signed-off-by: Michail Kargakis --- .../deployment/util/deployment_util.go | 25 -------------- pkg/controller/deployment/util/hash_test.go | 34 ++++++------------- pkg/controller/deployment/util/pod_util.go | 14 -------- .../deployment/util/replicaset_util.go | 10 ------ pkg/kubectl/stop_test.go | 15 ++------ 5 files changed, 13 insertions(+), 85 deletions(-) diff --git a/pkg/controller/deployment/util/deployment_util.go b/pkg/controller/deployment/util/deployment_util.go index bea58726571..1355d3eda05 100644 --- a/pkg/controller/deployment/util/deployment_util.go +++ b/pkg/controller/deployment/util/deployment_util.go @@ -746,31 +746,6 @@ func LabelPodsWithHash(podList *v1.PodList, c clientset.Interface, podLister cor return nil } -// GetNewReplicaSetTemplate returns the desired PodTemplateSpec for the new ReplicaSet corresponding to the given ReplicaSet. -// Callers of this helper need to set the DefaultDeploymentUniqueLabelKey k/v pair. -func GetNewReplicaSetTemplate(deployment *extensions.Deployment) v1.PodTemplateSpec { - // newRS will have the same template as in deployment spec. - return v1.PodTemplateSpec{ - ObjectMeta: deployment.Spec.Template.ObjectMeta, - Spec: deployment.Spec.Template.Spec, - } -} - -// TODO: remove the duplicate -// GetNewReplicaSetTemplateInternal returns the desired PodTemplateSpec for the new ReplicaSet corresponding to the given ReplicaSet. -func GetNewReplicaSetTemplateInternal(deployment *internalextensions.Deployment) api.PodTemplateSpec { - // newRS will have the same template as in deployment spec, plus a unique label in some cases. - newRSTemplate := api.PodTemplateSpec{ - ObjectMeta: deployment.Spec.Template.ObjectMeta, - Spec: deployment.Spec.Template.Spec, - } - newRSTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel( - deployment.Spec.Template.ObjectMeta.Labels, - internalextensions.DefaultDeploymentUniqueLabelKey, - fmt.Sprintf("%d", GetInternalPodTemplateSpecHash(newRSTemplate))) - return newRSTemplate -} - // SetFromReplicaSetTemplate sets the desired PodTemplateSpec from a replica set template to the given deployment. func SetFromReplicaSetTemplate(deployment *extensions.Deployment, template v1.PodTemplateSpec) *extensions.Deployment { deployment.Spec.Template.ObjectMeta = template.ObjectMeta diff --git a/pkg/controller/deployment/util/hash_test.go b/pkg/controller/deployment/util/hash_test.go index cdabe488876..b337540bfc6 100644 --- a/pkg/controller/deployment/util/hash_test.go +++ b/pkg/controller/deployment/util/hash_test.go @@ -18,11 +18,13 @@ package util import ( "encoding/json" + "hash/adler32" "strconv" "strings" "testing" "k8s.io/kubernetes/pkg/api/v1" + hashutil "k8s.io/kubernetes/pkg/util/hash" ) var podSpec string = ` @@ -103,34 +105,12 @@ var podSpec string = ` func TestPodTemplateSpecHash(t *testing.T) { seenHashes := make(map[uint32]int) - broken := false for i := 0; i < 1000; i++ { specJson := strings.Replace(podSpec, "@@VERSION@@", strconv.Itoa(i), 1) spec := v1.PodTemplateSpec{} json.Unmarshal([]byte(specJson), &spec) hash := GetPodTemplateSpecHash(spec) - if v, ok := seenHashes[hash]; ok { - broken = true - t.Logf("Hash collision, old: %d new: %d", v, i) - break - } - seenHashes[hash] = i - } - - if !broken { - t.Errorf("expected adler to break but it didn't") - } -} - -func TestPodTemplateSpecHashFnv(t *testing.T) { - seenHashes := make(map[uint32]int) - - for i := 0; i < 1000; i++ { - specJson := strings.Replace(podSpec, "@@VERSION@@", strconv.Itoa(i), 1) - spec := v1.PodTemplateSpec{} - json.Unmarshal([]byte(specJson), &spec) - hash := GetPodTemplateSpecHashFnv(spec) if v, ok := seenHashes[hash]; ok { t.Errorf("Hash collision, old: %d new: %d", v, i) break @@ -144,15 +124,21 @@ func BenchmarkAdler(b *testing.B) { json.Unmarshal([]byte(podSpec), &spec) for i := 0; i < b.N; i++ { - GetPodTemplateSpecHash(spec) + getPodTemplateSpecOldHash(spec) } } +func getPodTemplateSpecOldHash(template v1.PodTemplateSpec) uint32 { + podTemplateSpecHasher := adler32.New() + hashutil.DeepHashObject(podTemplateSpecHasher, template) + return podTemplateSpecHasher.Sum32() +} + func BenchmarkFnv(b *testing.B) { spec := v1.PodTemplateSpec{} json.Unmarshal([]byte(podSpec), &spec) for i := 0; i < b.N; i++ { - GetPodTemplateSpecHashFnv(spec) + GetPodTemplateSpecHash(spec) } } diff --git a/pkg/controller/deployment/util/pod_util.go b/pkg/controller/deployment/util/pod_util.go index b2d4e8464eb..80f7adc94f8 100644 --- a/pkg/controller/deployment/util/pod_util.go +++ b/pkg/controller/deployment/util/pod_util.go @@ -17,7 +17,6 @@ limitations under the License. package util import ( - "hash/adler32" "hash/fnv" "github.com/golang/glog" @@ -32,19 +31,6 @@ import ( ) func GetPodTemplateSpecHash(template v1.PodTemplateSpec) uint32 { - podTemplateSpecHasher := adler32.New() - hashutil.DeepHashObject(podTemplateSpecHasher, template) - return podTemplateSpecHasher.Sum32() -} - -// TODO: remove the duplicate -func GetInternalPodTemplateSpecHash(template api.PodTemplateSpec) uint32 { - podTemplateSpecHasher := adler32.New() - hashutil.DeepHashObject(podTemplateSpecHasher, template) - return podTemplateSpecHasher.Sum32() -} - -func GetPodTemplateSpecHashFnv(template v1.PodTemplateSpec) uint32 { podTemplateSpecHasher := fnv.New32a() hashutil.DeepHashObject(podTemplateSpecHasher, template) return podTemplateSpecHasher.Sum32() diff --git a/pkg/controller/deployment/util/replicaset_util.go b/pkg/controller/deployment/util/replicaset_util.go index 52f68eb9627..1e8b5f26993 100644 --- a/pkg/controller/deployment/util/replicaset_util.go +++ b/pkg/controller/deployment/util/replicaset_util.go @@ -77,13 +77,3 @@ func GetReplicaSetHash(rs *extensions.ReplicaSet) string { Spec: rs.Spec.Template.Spec, })) } - -// GetReplicaSetHashFnv returns the pod template hash of a ReplicaSet's pod template spec. -func GetReplicaSetHashFnv(rs *extensions.ReplicaSet) string { - meta := rs.Spec.Template.ObjectMeta - meta.Labels = labelsutil.CloneAndRemoveLabel(meta.Labels, extensions.DefaultDeploymentUniqueLabelKey) - return fmt.Sprintf("%d", GetPodTemplateSpecHashFnv(v1.PodTemplateSpec{ - ObjectMeta: meta, - Spec: rs.Spec.Template.Spec, - })) -} diff --git a/pkg/kubectl/stop_test.go b/pkg/kubectl/stop_test.go index 18db58da2f0..dd8752903e7 100644 --- a/pkg/kubectl/stop_test.go +++ b/pkg/kubectl/stop_test.go @@ -35,7 +35,6 @@ import ( "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake" coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion" - deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util" ) func TestReplicationControllerStop(t *testing.T) { @@ -441,7 +440,6 @@ func TestDeploymentStop(t *testing.T) { Replicas: 0, }, } - template := deploymentutil.GetNewReplicaSetTemplateInternal(&deployment) trueVar := true tests := []struct { Name string @@ -492,9 +490,7 @@ func TestDeploymentStop(t *testing.T) { }, }, }, - Spec: extensions.ReplicaSetSpec{ - Template: template, - }, + Spec: extensions.ReplicaSetSpec{}, }, // ReplicaSet owned by something else (should be ignored). { @@ -512,9 +508,7 @@ func TestDeploymentStop(t *testing.T) { }, }, }, - Spec: extensions.ReplicaSetSpec{ - Template: template, - }, + Spec: extensions.ReplicaSetSpec{}, }, }, }, @@ -709,7 +703,6 @@ func TestDeploymentNotFoundError(t *testing.T) { Replicas: 0, }, } - template := deploymentutil.GetNewReplicaSetTemplateInternal(deployment) fake := fake.NewSimpleClientset( deployment, @@ -719,9 +712,7 @@ func TestDeploymentNotFoundError(t *testing.T) { Name: name, Namespace: ns, }, - Spec: extensions.ReplicaSetSpec{ - Template: template, - }, + Spec: extensions.ReplicaSetSpec{}, }, }, },