Skip to content

Commit

Permalink
addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Mar 13, 2024
1 parent f9a6c55 commit e9a6b01
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/v1/aerospikecluster_validating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,7 @@ func isPathParentOrSame(dir1, dir2 string) bool {
}

func (c *AerospikeCluster) validatePodSpec() error {
if c.Spec.PodSpec.HostNetwork && ptr.Deref(c.Spec.PodSpec.MultiPodPerHost, false) {
if c.Spec.PodSpec.HostNetwork && GetBool(c.Spec.PodSpec.MultiPodPerHost) {
return fmt.Errorf("host networking cannot be enabled with multi pod per host")
}

Expand Down
6 changes: 6 additions & 0 deletions api/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

v1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

internalerrors "github.com/aerospike/aerospike-kubernetes-operator/errors"
lib "github.com/aerospike/aerospike-management-lib"
Expand Down Expand Up @@ -494,3 +495,8 @@ func getContainerNames(containers []v1.Container) []string {

return containerNames
}

// GetBool returns the value of the given bool pointer. If the pointer is nil, it returns false.
func GetBool(boolPtr *bool) bool {
return ptr.Deref(boolPtr, false)
}
3 changes: 1 addition & 2 deletions controllers/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"

asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
Expand Down Expand Up @@ -257,7 +256,7 @@ func (r *SingleClusterReconciler) getBaseConfData(rack *asdbv1.Rack) (map[string

initTemplateInput := initializeTemplateInput{
WorkDir: workDir,
MultiPodPerHost: ptr.Deref(r.aeroCluster.Spec.PodSpec.MultiPodPerHost, false),
MultiPodPerHost: asdbv1.GetBool(r.aeroCluster.Spec.PodSpec.MultiPodPerHost),
NetworkPolicy: r.aeroCluster.Spec.AerospikeNetworkPolicy,
PodPort: servicePortParam,
PodTLSPort: serviceTLSPortParam,
Expand Down
3 changes: 1 addition & 2 deletions controllers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
Expand Down Expand Up @@ -601,7 +600,7 @@ func (r *SingleClusterReconciler) cleanupPods(
}

// Try to delete corresponding pod service if it was created
if ptr.Deref(r.aeroCluster.Spec.PodSpec.MultiPodPerHost, false) {
if asdbv1.GetBool(r.aeroCluster.Spec.PodSpec.MultiPodPerHost) {
// Remove service for pod
// TODO: make it more robust, what if it fails
if err := r.deletePodService(
Expand Down
3 changes: 1 addition & 2 deletions controllers/rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
Expand Down Expand Up @@ -572,7 +571,7 @@ func (r *SingleClusterReconciler) reconcileRack(

// Safe check to delete all dangling pod services which are no longer required
// There won't be any case of dangling pod service with MultiPodPerHost false, so ignore that case
if ptr.Deref(r.aeroCluster.Spec.PodSpec.MultiPodPerHost, false) &&
if asdbv1.GetBool(r.aeroCluster.Spec.PodSpec.MultiPodPerHost) &&
!podServiceNeeded(r.aeroCluster.Spec.PodSpec.MultiPodPerHost, &r.aeroCluster.Spec.AerospikeNetworkPolicy) {
if err := r.cleanupDanglingPodServices(rackState); err != nil {
return reconcileError(err)
Expand Down
3 changes: 1 addition & 2 deletions controllers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1"
Expand Down Expand Up @@ -402,7 +401,7 @@ func (r *SingleClusterReconciler) cleanupDanglingPodServices(rackState *RackStat
}

func podServiceNeeded(multiPodPerHost *bool, networkPolicy *asdbv1.AerospikeNetworkPolicy) bool {
if !ptr.Deref(multiPodPerHost, false) || networkPolicy == nil {
if !asdbv1.GetBool(multiPodPerHost) || networkPolicy == nil {
return false
}

Expand Down
5 changes: 2 additions & 3 deletions controllers/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/util/retry"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

Expand Down Expand Up @@ -857,7 +856,7 @@ func (r *SingleClusterReconciler) updateSTSSchedulingPolicy(

// Set our rules in PodAntiAffinity
// only enable in production, so it can be used in 1 node clusters while debugging (minikube)
if !ptr.Deref(r.aeroCluster.Spec.PodSpec.MultiPodPerHost, false) {
if !asdbv1.GetBool(r.aeroCluster.Spec.PodSpec.MultiPodPerHost) {
if affinity.PodAntiAffinity == nil {
affinity.PodAntiAffinity = &corev1.PodAntiAffinity{}
}
Expand Down Expand Up @@ -1572,7 +1571,7 @@ func getSTSContainerPort(
// The container port will be exposed to the external network at <hostIP>:<hostPort>,
// where the hostIP is the IP address of the Kubernetes node where
// the container is running and the hostPort is the port requested by the user
if !ptr.Deref(multiPodPerHost, false) && portInfo.exposedOnHost {
if !asdbv1.GetBool(multiPodPerHost) && portInfo.exposedOnHost {
containerPort.HostPort = containerPort.ContainerPort
}

Expand Down
3 changes: 1 addition & 2 deletions test/aero_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/client"

as "github.com/aerospike/aerospike-client-go/v6"
Expand Down Expand Up @@ -62,7 +61,7 @@ func newAsConn(
tlsName := getServiceTLSName(aeroCluster)

networkType := asdbv1.AerospikeNetworkType(*defaultNetworkType)
if ptr.Deref(aeroCluster.Spec.PodSpec.MultiPodPerHost, false) && networkType != asdbv1.AerospikeNetworkTypePod &&
if asdbv1.GetBool(aeroCluster.Spec.PodSpec.MultiPodPerHost) && networkType != asdbv1.AerospikeNetworkTypePod &&
networkType != asdbv1.AerospikeNetworkTypeCustomInterface {
svc, err := getServiceForPod(pod, k8sClient)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/network_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ func getExpectedServicePortForPod(
var port int32

if (networkType != asdbv1.AerospikeNetworkTypePod && networkType != asdbv1.AerospikeNetworkTypeCustomInterface) &&
ptr.Deref(aeroCluster.Spec.PodSpec.MultiPodPerHost, false) {
asdbv1.GetBool(aeroCluster.Spec.PodSpec.MultiPodPerHost) {
svc, err := getServiceForPod(pod, k8sClient)
if err != nil {
return 0, fmt.Errorf("error getting service port: %v", err)
Expand Down

0 comments on commit e9a6b01

Please sign in to comment.