Merge pull request #43229 from mwielgus/cm-fix

Automatic merge from submit-queue

Fix federated config map unit tests

Fixes #41419 and #42847 and possibly other issues in this area.

cc: @nikhiljindal @csbell @perotinus
pull/6/head
Kubernetes Submit Queue 2017-03-18 05:08:18 -07:00 committed by GitHub
commit 8752bfb526
2 changed files with 31 additions and 19 deletions

View File

@ -323,13 +323,18 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
glog.V(8).Infof("Skipping not federated config map: %s", key) glog.V(8).Infof("Skipping not federated config map: %s", key)
return return
} }
baseConfigMap := baseConfigMapObj.(*apiv1.ConfigMap) obj, err := api.Scheme.DeepCopy(baseConfigMapObj)
configMap, ok := obj.(*apiv1.ConfigMap)
if err != nil || !ok {
glog.Errorf("Error in retrieving obj from store: %v, %v", ok, err)
return
}
// Check if deletion has been requested. // Check if deletion has been requested.
if baseConfigMap.DeletionTimestamp != nil { if configMap.DeletionTimestamp != nil {
if err := configmapcontroller.delete(baseConfigMap); err != nil { if err := configmapcontroller.delete(configMap); err != nil {
glog.Errorf("Failed to delete %s: %v", configmap, err) glog.Errorf("Failed to delete %s: %v", configmap, err)
configmapcontroller.eventRecorder.Eventf(baseConfigMap, api.EventTypeNormal, "DeleteFailed", configmapcontroller.eventRecorder.Eventf(configMap, api.EventTypeNormal, "DeleteFailed",
"ConfigMap delete failed: %v", err) "ConfigMap delete failed: %v", err)
configmapcontroller.deliverConfigMap(configmap, 0, true) configmapcontroller.deliverConfigMap(configmap, 0, true)
} }
@ -337,18 +342,18 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
} }
glog.V(3).Infof("Ensuring delete object from underlying clusters finalizer for configmap: %s", glog.V(3).Infof("Ensuring delete object from underlying clusters finalizer for configmap: %s",
baseConfigMap.Name) configMap.Name)
// Add the required finalizers before creating a configmap in underlying clusters. // Add the required finalizers before creating a configmap in underlying clusters.
updatedConfigMapObj, err := configmapcontroller.deletionHelper.EnsureFinalizers(baseConfigMap) updatedConfigMapObj, err := configmapcontroller.deletionHelper.EnsureFinalizers(configMap)
if err != nil { if err != nil {
glog.Errorf("Failed to ensure delete object from underlying clusters finalizer in configmap %s: %v", glog.Errorf("Failed to ensure delete object from underlying clusters finalizer in configmap %s: %v",
baseConfigMap.Name, err) configMap.Name, err)
configmapcontroller.deliverConfigMap(configmap, 0, false) configmapcontroller.deliverConfigMap(configmap, 0, false)
return return
} }
baseConfigMap = updatedConfigMapObj.(*apiv1.ConfigMap) configMap = updatedConfigMapObj.(*apiv1.ConfigMap)
glog.V(3).Infof("Syncing configmap %s in underlying clusters", baseConfigMap.Name) glog.V(3).Infof("Syncing configmap %s in underlying clusters", configMap.Name)
clusters, err := configmapcontroller.configmapFederatedInformer.GetReadyClusters() clusters, err := configmapcontroller.configmapFederatedInformer.GetReadyClusters()
if err != nil { if err != nil {
@ -368,12 +373,12 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
// Do not modify data. // Do not modify data.
desiredConfigMap := &apiv1.ConfigMap{ desiredConfigMap := &apiv1.ConfigMap{
ObjectMeta: util.DeepCopyRelevantObjectMeta(baseConfigMap.ObjectMeta), ObjectMeta: util.DeepCopyRelevantObjectMeta(configMap.ObjectMeta),
Data: baseConfigMap.Data, Data: configMap.Data,
} }
if !found { if !found {
configmapcontroller.eventRecorder.Eventf(baseConfigMap, api.EventTypeNormal, "CreateInCluster", configmapcontroller.eventRecorder.Eventf(configMap, api.EventTypeNormal, "CreateInCluster",
"Creating configmap in cluster %s", cluster.Name) "Creating configmap in cluster %s", cluster.Name)
operations = append(operations, util.FederatedOperation{ operations = append(operations, util.FederatedOperation{
@ -386,7 +391,7 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
// Update existing configmap, if needed. // Update existing configmap, if needed.
if !util.ConfigMapEquivalent(desiredConfigMap, clusterConfigMap) { if !util.ConfigMapEquivalent(desiredConfigMap, clusterConfigMap) {
configmapcontroller.eventRecorder.Eventf(baseConfigMap, api.EventTypeNormal, "UpdateInCluster", configmapcontroller.eventRecorder.Eventf(configMap, api.EventTypeNormal, "UpdateInCluster",
"Updating configmap in cluster %s", cluster.Name) "Updating configmap in cluster %s", cluster.Name)
operations = append(operations, util.FederatedOperation{ operations = append(operations, util.FederatedOperation{
Type: util.OperationTypeUpdate, Type: util.OperationTypeUpdate,
@ -404,7 +409,7 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
} }
err = configmapcontroller.federatedUpdater.UpdateWithOnError(operations, configmapcontroller.updateTimeout, err = configmapcontroller.federatedUpdater.UpdateWithOnError(operations, configmapcontroller.updateTimeout,
func(op util.FederatedOperation, operror error) { func(op util.FederatedOperation, operror error) {
configmapcontroller.eventRecorder.Eventf(baseConfigMap, api.EventTypeNormal, "UpdateInClusterFailed", configmapcontroller.eventRecorder.Eventf(configMap, api.EventTypeNormal, "UpdateInClusterFailed",
"ConfigMap update in cluster %s failed: %v", op.ClusterName, operror) "ConfigMap update in cluster %s failed: %v", op.ClusterName, operror)
}) })

View File

@ -143,11 +143,18 @@ func TestConfigMapController(t *testing.T) {
} }
configmapWatch.Modify(configmap1) configmapWatch.Modify(configmap1)
updatedConfigMap = GetConfigMapFromChan(cluster1UpdateChan) for {
assert.NotNil(t, updatedConfigMap) updatedConfigMap := GetConfigMapFromChan(cluster1UpdateChan)
assert.Equal(t, configmap1.Name, updatedConfigMap.Name) assert.NotNil(t, updatedConfigMap)
assert.Equal(t, configmap1.Namespace, updatedConfigMap.Namespace) if updatedConfigMap == nil {
assert.True(t, util.ConfigMapEquivalent(configmap1, updatedConfigMap)) break
}
assert.Equal(t, configmap1.Name, updatedConfigMap.Name)
assert.Equal(t, configmap1.Namespace, updatedConfigMap.Namespace)
if util.ConfigMapEquivalent(configmap1, updatedConfigMap) {
break
}
}
// Test add cluster // Test add cluster
clusterWatch.Add(cluster2) clusterWatch.Add(cluster2)