Skip to content

Commit

Permalink
overwrite user specified port in lb service
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Dec 13, 2023
1 parent 54a1b8f commit 2aa2834
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 49 deletions.
20 changes: 0 additions & 20 deletions api/v1/aerospikecluster_validating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ func (c *AerospikeCluster) ValidateUpdate(oldObj runtime.Object) (admission.Warn
return nil, err
}

// Validate Load Balancer update
if err := validateLoadBalancerUpdate(
aslog, c.Spec.SeedsFinderServices.LoadBalancer,
old.Spec.SeedsFinderServices.LoadBalancer,
); err != nil {
return nil, err
}

// Validate RackConfig update
return nil, c.validateRackUpdate(aslog, old)
}
Expand Down Expand Up @@ -1273,18 +1265,6 @@ func getNamespaceReplicationFactor(nsConf map[string]interface{}) (int, error) {
return rf, nil
}

func validateLoadBalancerUpdate(
aslog logr.Logger, newLBSpec, oldLBSpec *LoadBalancerSpec,
) error {
aslog.Info("Validate LoadBalancer update")

if oldLBSpec != nil && oldLBSpec.PortName != newLBSpec.PortName {
return fmt.Errorf("cannot update existing LoadBalancer Service name")
}

return nil
}

func validateSecurityConfigUpdate(
newVersion, oldVersion string, newSpec, oldSpec *AerospikeConfigSpec,
) error {
Expand Down
34 changes: 5 additions & 29 deletions controllers/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,30 +164,14 @@ func (r *SingleClusterReconciler) createOrUpdateSTSLoadBalancerSvc() error {
func (r *SingleClusterReconciler) updateLBService(service *corev1.Service, servicePort *corev1.ServicePort,
loadBalancer *asdbv1.LoadBalancerSpec) error {
updateLBService := false
aerospikePortNameFound := false

for idx := range service.Spec.Ports {
if service.Spec.Ports[idx].Name == servicePort.Name {
aerospikePortNameFound = true

if service.Spec.Ports[idx].Port != servicePort.Port ||
service.Spec.Ports[idx].TargetPort != servicePort.TargetPort {
service.Spec.Ports[idx].Port = servicePort.Port
service.Spec.Ports[idx].TargetPort = servicePort.TargetPort
updateLBService = true
}

break
}
}

// If there is no port name set for in port added by operator, then set it and overwrite ports set by user.
if !aerospikePortNameFound {
if len(service.Spec.Ports) != 1 || service.Spec.Ports[0].Port != servicePort.Port ||
service.Spec.Ports[0].TargetPort != servicePort.TargetPort ||
service.Spec.Ports[0].Name != servicePort.Name {
updateLBService = true
service.Spec.Ports = []corev1.ServicePort{
*servicePort,
}

updateLBService = true
}

if !reflect.DeepEqual(service.ObjectMeta.Annotations, loadBalancer.Annotations) {
Expand Down Expand Up @@ -394,17 +378,9 @@ func (r *SingleClusterReconciler) getLBServicePort(loadBalancer *asdbv1.LoadBala
port = targetPort
}

var portName string
if loadBalancer.PortName == "" {
// If port is specified in CR.
portName = "aerospikeport"
} else {
portName = loadBalancer.PortName
}

return corev1.ServicePort{
Port: port,
Name: portName,
Name: loadBalancer.PortName,
TargetPort: intstr.FromInt(int(targetPort)),
}
}
Expand Down

0 comments on commit 2aa2834

Please sign in to comment.