Skip to content

Commit

Permalink
controller: Make it so that last-applied-configuration isn't hashed (#15
Browse files Browse the repository at this point in the history
)

* controller: Make it so that last-applied-configuration isn't hashed

The annotation kubectl.kubernetes.io/last-applied-configuration
holds information about replica count. Including this annotation
makes it so that scaling operations (such as increasing or
decreasing regionserver replica count) will erroneously trigger
complete redeployment due to differing hash. Filter this annotation
out during calculation of statefuleset hash.

* controller: Make it so that last-applied-configuration isn't hashed

The annotation kubectl.kubernetes.io/last-applied-configuration
holds information about replica count. Including this annotation
makes it so that scaling operations (such as increasing or
decreasing regionserver replica count) will erroneously trigger
complete redeployment due to differing hash. Filter this annotation
out during calculation of statefuleset hash.

* controller: Make it so that last-applied-configuration isn't hashed

The annotation kubectl.kubernetes.io/last-applied-configuration
holds information about replica count. Including this annotation
makes it so that scaling operations (such as increasing or
decreasing regionserver replica count) will erroneously trigger
complete redeployment due to differing hash. Filter this annotation
out during calculation of statefuleset hash.

Co-authored-by: Michael Kwon <[email protected]>
  • Loading branch information
mskwon and mskwon authored Jul 13, 2021
1 parent 38f249b commit 2c6db60
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion controllers/hbase_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,25 @@ const (
HBaseControllerRevisionKey = "hbase-controller-revision"
)

var (
ignoreTemplateMetadataAnnotations = map[string]struct{}{
"kubectl.kubernetes.io/last-applied-configuration": struct{}{},
}
)

func (r *HBaseReconciler) statefulSet(hb *hbasev1.HBase,
stsName, cmName types.NamespacedName, ss hbasev1.ServerSpec) (*appsv1.StatefulSet, string) {
spec := (&ss.PodSpec).DeepCopy()
spec.Volumes = append(spec.Volumes, configMapVolume(cmName))

templateMetadataAnnotations := cloneMap(ss.Metadata.Annotations, hb.Annotations)
filteredTemplateMetadataAnnotations := make(map[string]string)
for k, v := range templateMetadataAnnotations {
if _, ok := ignoreTemplateMetadataAnnotations[k]; !ok {
filteredTemplateMetadataAnnotations[k] = v
}
}

stsSpec := appsv1.StatefulSetSpec{
PodManagementPolicy: appsv1.ParallelPodManagement,
// OnDelete because we managed the pod restarts ourselves
Expand All @@ -660,7 +675,7 @@ func (r *HBaseReconciler) statefulSet(hb *hbasev1.HBase,
Labels: cloneMap(ss.Metadata.Labels, hb.Labels, map[string]string{
HBaseControllerNameKey: stsName.Name,
}),
Annotations: cloneMap(ss.Metadata.Annotations, hb.Annotations),
Annotations: filteredTemplateMetadataAnnotations,
},
Spec: *spec,
},
Expand All @@ -673,6 +688,9 @@ func (r *HBaseReconciler) statefulSet(hb *hbasev1.HBase,
// After revision hash calculation, actually update replica count
stsSpec.Replicas = pointer.Int32Ptr(ss.Count)

// Restore metadata annotations without filtering
stsSpec.Template.ObjectMeta.Annotations = templateMetadataAnnotations

return &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: stsName.Name,
Expand Down

0 comments on commit 2c6db60

Please sign in to comment.