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

Fix federated config map unit tests #43229

Merged
merged 1 commit into from
Mar 18, 2017
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 @@ -323,32 +323,37 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
glog.V(8).Infof("Skipping not federated config map: %s", key)
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.
if baseConfigMap.DeletionTimestamp != nil {
if err := configmapcontroller.delete(baseConfigMap); err != nil {
if configMap.DeletionTimestamp != nil {
if err := configmapcontroller.delete(configMap); err != nil {
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)
configmapcontroller.deliverConfigMap(configmap, 0, true)
}
return
}

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.
updatedConfigMapObj, err := configmapcontroller.deletionHelper.EnsureFinalizers(baseConfigMap)
updatedConfigMapObj, err := configmapcontroller.deletionHelper.EnsureFinalizers(configMap)
if err != nil {
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)
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()
if err != nil {
Expand All @@ -368,12 +373,12 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ

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

if !found {
configmapcontroller.eventRecorder.Eventf(baseConfigMap, api.EventTypeNormal, "CreateInCluster",
configmapcontroller.eventRecorder.Eventf(configMap, api.EventTypeNormal, "CreateInCluster",
"Creating configmap in cluster %s", cluster.Name)

operations = append(operations, util.FederatedOperation{
Expand All @@ -386,7 +391,7 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ

// Update existing configmap, if needed.
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)
operations = append(operations, util.FederatedOperation{
Type: util.OperationTypeUpdate,
Expand All @@ -404,7 +409,7 @@ func (configmapcontroller *ConfigMapController) reconcileConfigMap(configmap typ
}
err = configmapcontroller.federatedUpdater.UpdateWithOnError(operations, configmapcontroller.updateTimeout,
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)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,18 @@ func TestConfigMapController(t *testing.T) {
}

configmapWatch.Modify(configmap1)
updatedConfigMap = GetConfigMapFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedConfigMap)
assert.Equal(t, configmap1.Name, updatedConfigMap.Name)
assert.Equal(t, configmap1.Namespace, updatedConfigMap.Namespace)
assert.True(t, util.ConfigMapEquivalent(configmap1, updatedConfigMap))
for {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix irks me, because it seems like the occasional double delivery should not be happening.

That said, it seems not worth the effort to fix this for real in light of upcoming work to refactor the federation controllers to use a common framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It happens because we are running controller with greatly reduced delay time. It is possible that the change doesn't get through the async mock transport layer before the config map is processed again. We could probably rethink the mocks but double delivery in this type of integration test with reduced delays will still be possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable. It still seems like this is an issue that could happen in the real world, but I suppose that's OK because it's still eventually consistent.

updatedConfigMap := GetConfigMapFromChan(cluster1UpdateChan)
assert.NotNil(t, updatedConfigMap)
if updatedConfigMap == nil {
break
}
assert.Equal(t, configmap1.Name, updatedConfigMap.Name)
assert.Equal(t, configmap1.Namespace, updatedConfigMap.Namespace)
if util.ConfigMapEquivalent(configmap1, updatedConfigMap) {
break
}
}

// Test add cluster
clusterWatch.Add(cluster2)
Expand Down