Skip to content

Commit

Permalink
KO-473 Add PSP feature gate (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
johntrimble committed Aug 20, 2020
1 parent e7d20fb commit a853063
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 21 deletions.
9 changes: 9 additions & 0 deletions mage/ginkgo/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,15 @@ func (ns NsWrapper) HelmInstall(chartPath string) {
mageutil.PanicOnError(err)
}

func (ns NsWrapper) HelmInstallWithPSPEnabled(chartPath string) {
var overrides = map[string]string{
"image": cfgutil.GetOperatorImage(),
"vmwarePSPEnabled": "true",
}
err := helm_util.Install(chartPath, "cass-operator", ns.Namespace, overrides)
mageutil.PanicOnError(err)
}

// Note that the actual value will be cast to a string before the comparison with the expectedValue
func (ns NsWrapper) ExpectKeyValue(m map[string]interface{}, key string, expectedValue string) {
actualValue, ok := m[key].(string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
api "github.com/datastax/cass-operator/operator/pkg/apis/cassandra/v1beta1"

"github.com/datastax/cass-operator/operator/pkg/oplabels"
"github.com/datastax/cass-operator/operator/pkg/utils"

"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
Expand Down Expand Up @@ -142,14 +143,16 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return requests
})

err = c.Watch(
&source.Kind{Type: &corev1.Node{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: mapFn,
},
)
if err != nil {
return err
if utils.IsPSPEnabled() {
err = c.Watch(
&source.Kind{Type: &corev1.Node{}},
&handler.EnqueueRequestsFromMapFunc{
ToRequests: mapFn,
},
)
if err != nil {
return err
}
}

// Setup watches for Secrets. These secrets are often not owned by or created by
Expand Down
10 changes: 6 additions & 4 deletions operator/pkg/reconciliation/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
api "github.com/datastax/cass-operator/operator/pkg/apis/cassandra/v1beta1"
"github.com/datastax/cass-operator/operator/pkg/dynamicwatch"
"github.com/datastax/cass-operator/operator/pkg/httphelper"
"github.com/datastax/cass-operator/operator/pkg/utils"
)

// Use a var so we can mock this function
Expand Down Expand Up @@ -124,10 +125,11 @@ func (rc *ReconciliationContext) updateNodeToDcMap() error {
func (rc *ReconciliationContext) calculateReconciliationActions() (reconcile.Result, error) {

rc.ReqLogger.Info("handler::calculateReconciliationActions")

if err := rc.updateNodeToDcMap(); err != nil {
// We will not skip reconciliation if the map update failed
// return result.Error(err).Output()
if utils.IsPSPEnabled() {
if err := rc.updateNodeToDcMap(); err != nil {
// We will not skip reconciliation if the map update failed
// return result.Error(err).Output()
}
}

// Check if the CassandraDatacenter was marked to be deleted
Expand Down
2 changes: 0 additions & 2 deletions operator/pkg/reconciliation/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestCalculateReconciliationActions_GetServiceError(t *testing.T) {

k8sMockClientGet(mockClient, fmt.Errorf(""))
k8sMockClientUpdate(mockClient, nil).Times(1)
k8sMockClientList(mockClient, nil).Times(1)
// k8sMockClientCreate(mockClient, nil)

_, err := rc.calculateReconciliationActions()
Expand All @@ -72,7 +71,6 @@ func TestCalculateReconciliationActions_FailedUpdate(t *testing.T) {
rc.Client = mockClient

k8sMockClientUpdate(mockClient, fmt.Errorf("failed to update CassandraDatacenter with removed finalizers"))
k8sMockClientList(mockClient, nil).Times(1)

_, err := rc.calculateReconciliationActions()
assert.Errorf(t, err, "Should have returned an error while calculating reconciliation actions")
Expand Down
9 changes: 6 additions & 3 deletions operator/pkg/reconciliation/reconcile_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

api "github.com/datastax/cass-operator/operator/pkg/apis/cassandra/v1beta1"
"github.com/datastax/cass-operator/operator/pkg/utils"
)

// ProcessDeletion ...
Expand All @@ -39,9 +40,11 @@ func (rc *ReconciliationContext) ProcessDeletion() result.ReconcileResult {
return result.Error(err)
}

rc.RemoveDcFromNodeToDcMap(types.NamespacedName{
Name: rc.Datacenter.GetName(),
Namespace: rc.Datacenter.GetNamespace()})
if utils.IsPSPEnabled() {
rc.RemoveDcFromNodeToDcMap(types.NamespacedName{
Name: rc.Datacenter.GetName(),
Namespace: rc.Datacenter.GetNamespace()})
}

// Update finalizer to allow delete of CassandraDatacenter
rc.Datacenter.SetFinalizers(nil)
Expand Down
8 changes: 5 additions & 3 deletions operator/pkg/reconciliation/reconcile_racks.go
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ func (rc *ReconciliationContext) deleteStuckNodes() (bool, error) {
} else if isNodeStuckAfterLosingReadiness(pod) {
reason = "Pod got stuck after losing readiness"
shouldDelete = true
} else if rc.isNodeStuckWithoutPVC(pod) {
} else if utils.IsPSPEnabled() && rc.isNodeStuckWithoutPVC(pod) {
reason = "Pod got stuck waiting for PersistentValueClaim"
shouldDelete = true
}
Expand Down Expand Up @@ -2106,8 +2106,10 @@ func (rc *ReconciliationContext) ReconcileAllRacks() (reconcile.Result, error) {

// We do the node taint check here, with the assumption that the cluster is "healthy"

if err := rc.checkNodeTaints(); err != nil {
return result.Error(err).Output()
if utils.IsPSPEnabled() {
if err := rc.checkNodeTaints(); err != nil {
return result.Error(err).Output()
}
}

// TODO until we ignore status updates as it pertains to reconcile
Expand Down
10 changes: 10 additions & 0 deletions operator/pkg/utils/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

package utils

import (
"os"
"strings"
)

func IsPSPEnabled() bool {
value, exists := os.LookupEnv("ENABLE_VMWARE_PSP")
return exists && "true" == strings.TrimSpace(value)
}

// MergeMap will take two maps, merging the entries of the source map into destination map. If both maps share the same key
// then destination's value for that key will be overwritten with what's in source.
func MergeMap(destination map[string]string, sources ...map[string]string) map[string]string {
Expand Down
2 changes: 1 addition & 1 deletion tests/tolerations/tolerations_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe(testName, func() {
Expect(err).ToNot(HaveOccurred())

step := "setting up cass-operator resources via helm chart"
ns.HelmInstall("../../charts/cass-operator-chart")
ns.HelmInstallWithPSPEnabled("../../charts/cass-operator-chart")

ns.WaitForOperatorReady()

Expand Down

0 comments on commit a853063

Please sign in to comment.