Skip to content

Commit fff04ac

Browse files
authored
Add frozen field to cluster spec that will suspend changes (#241)
1 parent 12ebef6 commit fff04ac

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ ClusterSpec defines the desired state for a M3 cluster to be converge to.
6969
| podMetadata | PodMetadata is for any Metadata that is unique to the pods, and does not belong on any other objects, such as Prometheus scrape tags | [metav1.ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#objectmeta-v1-meta) | false |
7070
| parallelPodManagement | ParallelPodManagement sets StatefulSets created by the operator to have Parallel pod management instead of OrderedReady. This is an EXPERIMENTAL flag and subject to deprecation in a future release. This has not been tested in production and users should not depend on it without validating it for their own use case. | bool | true |
7171
| serviceAccountName | To use a non-default service account, specify the name here otherwise the service account \"default\" will be used. This is useful for advanced use-cases such as pod security policies. The service account must exist. This operator will not create it. | string | false |
72+
| frozen | Frozen is used to stop the operator from taking any further actions on a cluster. This is useful when troubleshooting as it guarantees the operator won't make any changes to the cluster. | bool | false |
7273

7374
[Back to TOC](#table-of-contents)
7475

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ require (
4343
github.com/uber-go/tally v3.3.13+incompatible
4444
github.com/ultraware/funlen v0.0.2 // indirect
4545
github.com/urfave/cli v1.22.2 // indirect
46+
go.uber.org/atomic v1.6.0
4647
go.uber.org/zap v1.13.0
4748
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
4849
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 // indirect

pkg/apis/m3dboperator/v1alpha1/cluster.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ type ClusterSpec struct {
306306
// use-cases such as pod security policies. The service account must exist.
307307
// This operator will not create it.
308308
ServiceAccountName string `json:"serviceAccountName,omitempty"`
309+
310+
// Frozen is used to stop the operator from taking any further actions on a
311+
// cluster. This is useful when troubleshooting as it guarantees the operator
312+
// won't make any changes to the cluster.
313+
// +optional
314+
Frozen bool `json:"frozen,omitempty"`
309315
}
310316

311317
// ExternalCoordinatorConfig defines parameters for using an external

pkg/apis/m3dboperator/v1alpha1/openapi_generated.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ func (c *M3DBController) handleClusterUpdate(cluster *myspec.M3DBCluster) error
358358

359359
clusterLogger := c.logger.With(zap.String("cluster", cluster.Name))
360360

361+
if cluster.Spec.Frozen {
362+
clusterLogger.Info("cluster is frozen so no changes will be made")
363+
return nil
364+
}
365+
361366
// https://v1-12.docs.kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/
362367
//
363368
// If deletion timestamp is zero (cluster hasn't been deleted), make sure our

pkg/controller/controller_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import (
5757
"github.com/stretchr/testify/assert"
5858
"github.com/stretchr/testify/require"
5959
"github.com/uber-go/tally"
60+
"go.uber.org/atomic"
6061
"go.uber.org/zap"
6162
)
6263

@@ -784,3 +785,36 @@ func TestHandleUpdateClusterUpdatesStatefulSets(t *testing.T) {
784785
})
785786
}
786787
}
788+
789+
func TestHandleUpdateClusterFrozen(t *testing.T) {
790+
791+
var (
792+
clusterMeta = newMeta("cluster1", map[string]string{
793+
"foo": "bar",
794+
"operator.m3db.io/app": "m3db",
795+
"operator.m3db.io/cluster": "cluster1",
796+
}, nil)
797+
sets = []*metav1.ObjectMeta{
798+
newMeta("cluster1-rep0", nil, nil),
799+
}
800+
)
801+
cluster, deps := setupTestCluster(t, *clusterMeta, sets, 3)
802+
defer deps.cleanup()
803+
controller := deps.newController(t)
804+
805+
cluster.Spec.Frozen = true
806+
807+
count := atomic.NewInt64(0)
808+
controller.kubeClient.(*kubefake.Clientset).PrependReactor(
809+
"*", "*", func(action ktesting.Action) (bool, runtime.Object, error) {
810+
count.Inc()
811+
return false, nil, nil
812+
})
813+
814+
for i := 0; i < 20; i++ {
815+
err := controller.handleClusterUpdate(cluster)
816+
require.NoError(t, err)
817+
}
818+
819+
assert.Equal(t, int64(0), count.Load())
820+
}

0 commit comments

Comments
 (0)