Skip to content

Commit

Permalink
removing commented code and fixing lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Oct 31, 2023
1 parent f87b365 commit 333c19a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
15 changes: 6 additions & 9 deletions controllers/aerospikecluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,15 @@ type AerospikeClusterReconciler struct {
}

func stsPodPendingPredicate(e event.UpdateEvent) bool {
if e.ObjectOld == nil {
return false
}
if e.ObjectNew == nil {
if e.ObjectOld == nil || e.ObjectNew == nil {
return false
}

oldSTS, ok := e.ObjectOld.(*appsv1.StatefulSet)
if !ok {
return false
}

newSTS, ok := e.ObjectNew.(*appsv1.StatefulSet)
if !ok {
return false
Expand All @@ -76,7 +74,7 @@ type StatusPendingPredicate struct {
predicate.Funcs
}

// Update implements default UpdateEvent filter for validating available replicas change.
// Update implements default UpdateEvent filter for statefulSets.
func (StatusPendingPredicate) Update(e event.UpdateEvent) bool {
return stsPodPendingPredicate(e)
}
Expand All @@ -91,9 +89,7 @@ func (r *AerospikeClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
CreateFunc: func(e event.CreateEvent) bool {
return false
},
UpdateFunc: func(e event.UpdateEvent) bool {
return stsPodPendingPredicate(e)
},
UpdateFunc: stsPodPendingPredicate,
},
),
).
Expand All @@ -102,7 +98,8 @@ func (r *AerospikeClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
MaxConcurrentReconciles: maxConcurrentReconciles,
},
).
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{}, StatusPendingPredicate{})).
WithEventFilter(predicate.Or(predicate.GenerationChangedPredicate{}, predicate.LabelChangedPredicate{},
StatusPendingPredicate{})).
Complete(r)
}

Expand Down
11 changes: 6 additions & 5 deletions controllers/pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package controllers
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/types"
"strconv"
"time"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
Expand Down Expand Up @@ -117,17 +117,18 @@ func (r *SingleClusterReconciler) deleteLocalPVCs(pod *corev1.Pod) error {
return fmt.Errorf("could not find pvc for pod %v: %v", pod.Name, err)
}

for _, pvc := range pvcItems {
for idx := range pvcItems {
pv := &corev1.PersistentVolume{}
pvName := types.NamespacedName{Name: pvc.Spec.VolumeName}
pvName := types.NamespacedName{Name: pvcItems[idx].Spec.VolumeName}

if err := r.Client.Get(context.TODO(), pvName, pv); err != nil {
return err
}

if pv.Spec.Local != nil {
if err := r.Client.Delete(context.TODO(), &pvc); err != nil {
if err := r.Client.Delete(context.TODO(), &pvcItems[idx]); err != nil {
return fmt.Errorf(
"could not delete pvc %s: %v", pvc.Name, err,
"could not delete pvc %s: %v", pvcItems[idx].Name, err,
)
}
}
Expand Down
22 changes: 5 additions & 17 deletions controllers/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,31 +598,16 @@ func (r *SingleClusterReconciler) updateSTS(
// TODO: Add validation. device, file, both should not exist in same storage class
r.updateSTSStorage(statefulSet, rackState)

// Save the updated stateful set.
// Can we optimize this? Update stateful set only if there is any change
// in it.
/* currentSTS, err := r.getSTS(rackState)
if err != nil {
return err
}
if reflect.DeepEqual(currentSTS.Spec, statefulSet.Spec) {
r.Log.Info("statefulset update not needed, no change in spec", "stsName", currentSTS.Name)
return nil
}
*/

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
found, err := r.getSTS(rackState)
if err != nil {
return err
}
r.Log.Info("print both sts spec", "getsts", found.Spec, "statefulSet", statefulSet.Spec)

if reflect.DeepEqual(found.Spec, statefulSet.Spec) {
r.Log.Info("StatefulSet update not needed, no change in spec", "stsName", found.Name)
return nil
}
// Save the updated stateful set.
found.Spec = statefulSet.Spec
return r.Client.Update(context.TODO(), found, updateOption)
})
Expand Down Expand Up @@ -798,12 +783,14 @@ func (r *SingleClusterReconciler) updateSTSNonPVStorage(
// Add volume in statefulSet template
perm := corev1.SecretVolumeSourceDefaultMode
k8sVolume := createVolumeForVolumeAttachment(volume)

switch {
case k8sVolume.Secret != nil:
k8sVolume.Secret.DefaultMode = &perm
case k8sVolume.ConfigMap != nil:
k8sVolume.ConfigMap.DefaultMode = &perm
}

st.Spec.Template.Spec.Volumes = append(
st.Spec.Template.Spec.Volumes, k8sVolume,
)
Expand Down Expand Up @@ -1219,6 +1206,7 @@ func getDefaultSTSVolumes(
aeroCluster *asdbv1.AerospikeCluster, rackState *RackState,
) []corev1.Volume {
defaultMode := corev1.SecretVolumeSourceDefaultMode

return []corev1.Volume{
{
Name: confDirName,
Expand Down
1 change: 1 addition & 0 deletions test/cluster_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ func getStorageVolumeForAerospike(name, path string) asdbv1.VolumeSpec {

func getStorageVolumeForSecret() asdbv1.VolumeSpec {
perm := corev1.SecretVolumeSourceDefaultMode

return asdbv1.VolumeSpec{
Name: aerospikeConfigSecret,
Source: asdbv1.VolumeSource{
Expand Down

0 comments on commit 333c19a

Please sign in to comment.