Remove obsolete deployment helpers

Signed-off-by: Michail Kargakis <mkargaki@redhat.com>
This commit is contained in:
Michail Kargakis 2017-04-21 16:47:32 +02:00
parent 4aa8b1a66a
commit fcf68ba7a7
No known key found for this signature in database
GPG Key ID: EA0DEBF5DFA276E0
5 changed files with 13 additions and 85 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -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()

View File

@ -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,
}))
}

View File

@ -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{},
},
},
},