mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Remove obsolete deployment helpers
Signed-off-by: Michail Kargakis <mkargaki@redhat.com>
This commit is contained in:
parent
4aa8b1a66a
commit
fcf68ba7a7
@ -746,31 +746,6 @@ func LabelPodsWithHash(podList *v1.PodList, c clientset.Interface, podLister cor
|
|||||||
return nil
|
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.
|
// SetFromReplicaSetTemplate sets the desired PodTemplateSpec from a replica set template to the given deployment.
|
||||||
func SetFromReplicaSetTemplate(deployment *extensions.Deployment, template v1.PodTemplateSpec) *extensions.Deployment {
|
func SetFromReplicaSetTemplate(deployment *extensions.Deployment, template v1.PodTemplateSpec) *extensions.Deployment {
|
||||||
deployment.Spec.Template.ObjectMeta = template.ObjectMeta
|
deployment.Spec.Template.ObjectMeta = template.ObjectMeta
|
||||||
|
@ -18,11 +18,13 @@ package util
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"hash/adler32"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
|
hashutil "k8s.io/kubernetes/pkg/util/hash"
|
||||||
)
|
)
|
||||||
|
|
||||||
var podSpec string = `
|
var podSpec string = `
|
||||||
@ -103,34 +105,12 @@ var podSpec string = `
|
|||||||
|
|
||||||
func TestPodTemplateSpecHash(t *testing.T) {
|
func TestPodTemplateSpecHash(t *testing.T) {
|
||||||
seenHashes := make(map[uint32]int)
|
seenHashes := make(map[uint32]int)
|
||||||
broken := false
|
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
specJson := strings.Replace(podSpec, "@@VERSION@@", strconv.Itoa(i), 1)
|
specJson := strings.Replace(podSpec, "@@VERSION@@", strconv.Itoa(i), 1)
|
||||||
spec := v1.PodTemplateSpec{}
|
spec := v1.PodTemplateSpec{}
|
||||||
json.Unmarshal([]byte(specJson), &spec)
|
json.Unmarshal([]byte(specJson), &spec)
|
||||||
hash := GetPodTemplateSpecHash(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 {
|
if v, ok := seenHashes[hash]; ok {
|
||||||
t.Errorf("Hash collision, old: %d new: %d", v, i)
|
t.Errorf("Hash collision, old: %d new: %d", v, i)
|
||||||
break
|
break
|
||||||
@ -144,15 +124,21 @@ func BenchmarkAdler(b *testing.B) {
|
|||||||
json.Unmarshal([]byte(podSpec), &spec)
|
json.Unmarshal([]byte(podSpec), &spec)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
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) {
|
func BenchmarkFnv(b *testing.B) {
|
||||||
spec := v1.PodTemplateSpec{}
|
spec := v1.PodTemplateSpec{}
|
||||||
json.Unmarshal([]byte(podSpec), &spec)
|
json.Unmarshal([]byte(podSpec), &spec)
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
GetPodTemplateSpecHashFnv(spec)
|
GetPodTemplateSpecHash(spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"hash/adler32"
|
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
@ -32,19 +31,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetPodTemplateSpecHash(template v1.PodTemplateSpec) uint32 {
|
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()
|
podTemplateSpecHasher := fnv.New32a()
|
||||||
hashutil.DeepHashObject(podTemplateSpecHasher, template)
|
hashutil.DeepHashObject(podTemplateSpecHasher, template)
|
||||||
return podTemplateSpecHasher.Sum32()
|
return podTemplateSpecHasher.Sum32()
|
||||||
|
@ -77,13 +77,3 @@ func GetReplicaSetHash(rs *extensions.ReplicaSet) string {
|
|||||||
Spec: rs.Spec.Template.Spec,
|
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,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
@ -35,7 +35,6 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
|
||||||
coreclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/internalversion"
|
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) {
|
func TestReplicationControllerStop(t *testing.T) {
|
||||||
@ -441,7 +440,6 @@ func TestDeploymentStop(t *testing.T) {
|
|||||||
Replicas: 0,
|
Replicas: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
template := deploymentutil.GetNewReplicaSetTemplateInternal(&deployment)
|
|
||||||
trueVar := true
|
trueVar := true
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Name string
|
Name string
|
||||||
@ -492,9 +490,7 @@ func TestDeploymentStop(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: extensions.ReplicaSetSpec{
|
Spec: extensions.ReplicaSetSpec{},
|
||||||
Template: template,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
// ReplicaSet owned by something else (should be ignored).
|
// ReplicaSet owned by something else (should be ignored).
|
||||||
{
|
{
|
||||||
@ -512,9 +508,7 @@ func TestDeploymentStop(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: extensions.ReplicaSetSpec{
|
Spec: extensions.ReplicaSetSpec{},
|
||||||
Template: template,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -709,7 +703,6 @@ func TestDeploymentNotFoundError(t *testing.T) {
|
|||||||
Replicas: 0,
|
Replicas: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
template := deploymentutil.GetNewReplicaSetTemplateInternal(deployment)
|
|
||||||
|
|
||||||
fake := fake.NewSimpleClientset(
|
fake := fake.NewSimpleClientset(
|
||||||
deployment,
|
deployment,
|
||||||
@ -719,9 +712,7 @@ func TestDeploymentNotFoundError(t *testing.T) {
|
|||||||
Name: name,
|
Name: name,
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
},
|
},
|
||||||
Spec: extensions.ReplicaSetSpec{
|
Spec: extensions.ReplicaSetSpec{},
|
||||||
Template: template,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user