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

Make desired objects in fed controller reconcilation function fully writable #36399

Merged
merged 1 commit into from
Nov 21, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
return
}

// Do not modify data.
desiredConfigMap := &api_v1.ConfigMap{
ObjectMeta: util.CopyObjectMeta(baseConfigMap.ObjectMeta),
ObjectMeta: util.DeepCopyRelevantObjectMeta(baseConfigMap.ObjectMeta),
Data: baseConfigMap.Data,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,10 @@ func (daemonsetcontroller *DaemonSetController) reconcileDaemonSet(namespace str
return
}

// Do not modify. Otherwise make a deep copy.
desiredDaemonSet := &extensionsv1.DaemonSet{
ObjectMeta: util.CopyObjectMeta(baseDaemonSet.ObjectMeta),
Spec: baseDaemonSet.Spec,
ObjectMeta: util.DeepCopyRelevantObjectMeta(baseDaemonSet.ObjectMeta),
Spec: util.DeepCopyApiTypeOrPanic(baseDaemonSet.Spec).(extensionsv1.DaemonSetSpec),
}

if !found {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,10 @@ func (fdc *DeploymentController) reconcileDeployment(key string) (reconciliation
return statusError, err
}

// The object can be modified.
ld := &extensionsv1.Deployment{
ObjectMeta: fedutil.CopyObjectMeta(fd.ObjectMeta),
Spec: fd.Spec,
ObjectMeta: fedutil.DeepCopyRelevantObjectMeta(fd.ObjectMeta),
Spec: fedutil.DeepCopyApiTypeOrPanic(fd.Spec).(extensionsv1.DeploymentSpec),
}
specReplicas := int32(replicas)
ld.Spec.Replicas = &specReplicas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func (ic *IngressController) reconcileIngress(ingress types.NamespacedName) {
if !clusterIngressFound {
glog.V(4).Infof("No existing Ingress %s in cluster %s - checking if appropriate to queue a create operation", ingress, cluster.Name)
// We can't supply server-created fields when creating a new object.
desiredIngress.ObjectMeta = util.DeepCopyObjectMeta(baseIngress.ObjectMeta)
desiredIngress.ObjectMeta = util.DeepCopyRelevantObjectMeta(baseIngress.ObjectMeta)
ic.eventRecorder.Eventf(baseIngress, api.EventTypeNormal, "CreateInCluster",
"Creating ingress in cluster %s", cluster.Name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,10 @@ func (nc *NamespaceController) reconcileNamespace(namespace string) {
nc.deliverNamespace(namespace, 0, true)
return
}
// The object should not be modified.
desiredNamespace := &api_v1.Namespace{
ObjectMeta: util.CopyObjectMeta(baseNamespace.ObjectMeta),
Spec: baseNamespace.Spec,
ObjectMeta: util.DeepCopyRelevantObjectMeta(baseNamespace.ObjectMeta),
Spec: util.DeepCopyApiTypeOrPanic(baseNamespace.Spec).(api_v1.NamespaceSpec),
}
glog.V(5).Infof("Desired namespace in underlying clusters: %+v", desiredNamespace)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,10 @@ func (frsc *ReplicaSetController) reconcileReplicaSet(key string) (reconciliatio
return statusError, err
}

// The object can be modified.
lrs := &extensionsv1.ReplicaSet{
ObjectMeta: fedutil.CopyObjectMeta(frs.ObjectMeta),
Spec: frs.Spec,
ObjectMeta: fedutil.DeepCopyRelevantObjectMeta(frs.ObjectMeta),
Spec: fedutil.DeepCopyApiTypeOrPanic(frs.Spec).(extensionsv1.ReplicaSetSpec),
}
specReplicas := int32(replicas)
lrs.Spec.Replicas = &specReplicas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ func (secretcontroller *SecretController) reconcileSecret(secret types.Namespace
return
}

// The data should not be modified.
desiredSecret := &api_v1.Secret{
ObjectMeta: util.CopyObjectMeta(baseSecret.ObjectMeta),
ObjectMeta: util.DeepCopyRelevantObjectMeta(baseSecret.ObjectMeta),
Data: baseSecret.Data,
Type: baseSecret.Type,
}
Expand Down
1 change: 1 addition & 0 deletions federation/pkg/federation-controller/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ go_library(
"//pkg/client/restclient:go_default_library",
"//pkg/client/unversioned/clientcmd:go_default_library",
"//pkg/client/unversioned/clientcmd/api:go_default_library",
"//pkg/conversion:go_default_library",
"//pkg/runtime:go_default_library",
"//pkg/util/flowcontrol:go_default_library",
"//pkg/util/net:go_default_library",
Expand Down
15 changes: 12 additions & 3 deletions federation/pkg/federation-controller/util/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"reflect"

api_v1 "k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/conversion"
"k8s.io/kubernetes/pkg/runtime"
)

// Copies cluster-independent, user provided data from the given ObjectMeta struct. If in
// the future the ObjectMeta structure is expanded then any field that is not populated
// by the api server should be included here.
func CopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
func copyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
return api_v1.ObjectMeta{
Name: obj.Name,
Namespace: obj.Namespace,
Expand All @@ -38,8 +39,8 @@ func CopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
// Deep copies cluster-independent, user provided data from the given ObjectMeta struct. If in
// the future the ObjectMeta structure is expanded then any field that is not populated
// by the api server should be included here.
func DeepCopyObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
copyMeta := CopyObjectMeta(obj)
func DeepCopyRelevantObjectMeta(obj api_v1.ObjectMeta) api_v1.ObjectMeta {
copyMeta := copyObjectMeta(obj)
if obj.Labels != nil {
copyMeta.Labels = make(map[string]string)
for key, val := range obj.Labels {
Expand Down Expand Up @@ -83,3 +84,11 @@ func ObjectMetaAndSpecEquivalent(a, b runtime.Object) bool {
specB := reflect.ValueOf(b).Elem().FieldByName("Spec").Interface()
return ObjectMetaEquivalent(objectMetaA, objectMetaB) && reflect.DeepEqual(specA, specB)
}

func DeepCopyApiTypeOrPanic(item interface{}) interface{} {
result, err := conversion.NewCloner().DeepCopy(item)
if err != nil {
panic(err)
}
return result
}
2 changes: 1 addition & 1 deletion federation/pkg/federation-controller/util/meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestObjectMeta(t *testing.T) {
UID: "1231231412",
ResourceVersion: "999",
}
o2 := CopyObjectMeta(o1)
o2 := copyObjectMeta(o1)
o3 := api_v1.ObjectMeta{
Namespace: "ns1",
Name: "s1",
Expand Down