Skip to content

Commit

Permalink
(split) operator: Change the external connectivity occurrence
Browse files Browse the repository at this point in the history
In the source code where the boolean external connectivity was used
the Enabled access was added. In the test the new struct was
initialized.
  • Loading branch information
RafalKorepta committed Mar 17, 2021
1 parent cc80c08 commit 7547e68
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions apis/redpanda/v1alpha1/cluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ func (r *Cluster) checkCollidingPorts() field.ErrorList {
"admin port collide with Spec.Configuration.RPCServer.Port"))
}

if r.Spec.ExternalConnectivity && r.Spec.Configuration.KafkaAPI.Port+1 == r.Spec.Configuration.RPCServer.Port {
if r.Spec.ExternalConnectivity.Enabled && r.Spec.Configuration.KafkaAPI.Port+1 == r.Spec.Configuration.RPCServer.Port {
allErrs = append(allErrs,
field.Invalid(field.NewPath("spec").Child("configuration", "rpcServer", "port"),
r.Spec.Configuration.RPCServer.Port,
"rpc port collide with external Kafka API that is not visible in the Cluster CR"))
}

if r.Spec.ExternalConnectivity && r.Spec.Configuration.KafkaAPI.Port+1 == r.Spec.Configuration.AdminAPI.Port {
if r.Spec.ExternalConnectivity.Enabled && r.Spec.Configuration.KafkaAPI.Port+1 == r.Spec.Configuration.AdminAPI.Port {
allErrs = append(allErrs,
field.Invalid(field.NewPath("spec").Child("configuration", "admin", "port"),
r.Spec.Configuration.AdminAPI.Port,
Expand Down
23 changes: 16 additions & 7 deletions apis/redpanda/v1alpha1/cluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ func TestValidateUpdate(t *testing.T) {
corev1.ResourceMemory: resource.MustParse("1Gi"),
},
},
ExternalConnectivity: false,
ExternalConnectivity: v1alpha1.ExternalConnectivityConfig{
Enabled: false,
Subdomain: "",
},
},
}

Expand Down Expand Up @@ -101,7 +104,10 @@ func TestValidateUpdate_NoError(t *testing.T) {
corev1.ResourceMemory: resource.MustParse("2Gi"),
},
},
ExternalConnectivity: false,
ExternalConnectivity: v1alpha1.ExternalConnectivityConfig{
Enabled: false,
Subdomain: "",
},
},
}

Expand Down Expand Up @@ -138,7 +144,7 @@ func TestValidateUpdate_NoError(t *testing.T) {

t.Run("collision in the port when external connectivity is enabled", func(t *testing.T) {
updatePort := redpandaCluster.DeepCopy()
updatePort.Spec.ExternalConnectivity = true
updatePort.Spec.ExternalConnectivity.Enabled = true
updatePort.Spec.Configuration.KafkaAPI.Port = 200
updatePort.Spec.Configuration.AdminAPI.Port = 201
updatePort.Spec.Configuration.RPCServer.Port = 300
Expand All @@ -149,7 +155,7 @@ func TestValidateUpdate_NoError(t *testing.T) {

t.Run("collision in the port when external connectivity is enabled", func(t *testing.T) {
updatePort := redpandaCluster.DeepCopy()
updatePort.Spec.ExternalConnectivity = true
updatePort.Spec.ExternalConnectivity.Enabled = true
updatePort.Spec.Configuration.KafkaAPI.Port = 200
updatePort.Spec.Configuration.AdminAPI.Port = 300
updatePort.Spec.Configuration.RPCServer.Port = 201
Expand Down Expand Up @@ -185,7 +191,10 @@ func TestCreation(t *testing.T) {
corev1.ResourceMemory: resource.MustParse("2G"),
},
},
ExternalConnectivity: false,
ExternalConnectivity: v1alpha1.ExternalConnectivityConfig{
Enabled: false,
Subdomain: "",
},
},
}

Expand All @@ -209,7 +218,7 @@ func TestCreation(t *testing.T) {

t.Run("collision in the port when external connectivity is enabled", func(t *testing.T) {
newPort := redpandaCluster.DeepCopy()
newPort.Spec.ExternalConnectivity = true
newPort.Spec.ExternalConnectivity.Enabled = true
newPort.Spec.Configuration.KafkaAPI.Port = 200
newPort.Spec.Configuration.AdminAPI.Port = 201
newPort.Spec.Configuration.RPCServer.Port = 300
Expand All @@ -220,7 +229,7 @@ func TestCreation(t *testing.T) {

t.Run("collision in the port when external connectivity is enabled", func(t *testing.T) {
newPort := redpandaCluster.DeepCopy()
newPort.Spec.ExternalConnectivity = true
newPort.Spec.ExternalConnectivity.Enabled = true
newPort.Spec.Configuration.KafkaAPI.Port = 200
newPort.Spec.Configuration.AdminAPI.Port = 300
newPort.Spec.Configuration.RPCServer.Port = 201
Expand Down
2 changes: 1 addition & 1 deletion controllers/redpanda/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (r *ClusterReconciler) createExternalNodesList(
pandaCluster *redpandav1alpha1.Cluster,
nodePortName types.NamespacedName,
) ([]string, error) {
if !pandaCluster.Spec.ExternalConnectivity {
if !pandaCluster.Spec.ExternalConnectivity.Enabled {
return []string{}, nil
}

Expand Down
5 changes: 4 additions & 1 deletion controllers/redpanda/cluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ var _ = Describe("RedPandaCluster controller", func() {
Limits: resources,
Requests: resources,
},
ExternalConnectivity: true,
ExternalConnectivity: v1alpha1.ExternalConnectivityConfig{
Enabled: true,
Subdomain: "",
},
},
}
Expect(k8sClient.Create(context.Background(), redpandaCluster)).Should(Succeed())
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/cluster_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewClusterRole(

// Ensure manages v1.ClusterRole that is assigned to v1.ServiceAccount used in initContainer
func (r *ClusterRoleResource) Ensure(ctx context.Context) error {
if !r.pandaCluster.Spec.ExternalConnectivity {
if !r.pandaCluster.Spec.ExternalConnectivity.Enabled {
return nil
}
_, err := CreateIfNotExists(ctx, r, r.obj(), r.logger)
Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/cluster_role_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewClusterRoleBinding(

// Ensure manages v1.ClusterRoleBinding that is assigned to v1.ServiceAccount used in initContainer
func (r *ClusterRoleBindingResource) Ensure(ctx context.Context) error {
if !r.pandaCluster.Spec.ExternalConnectivity {
if !r.pandaCluster.Spec.ExternalConnectivity.Enabled {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/node_port_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewNodePortService(

// Ensure will manage kubernetes v1.Service for redpanda.vectorized.io custom resource
func (r *NodePortServiceResource) Ensure(ctx context.Context) error {
if !r.pandaCluster.Spec.ExternalConnectivity {
if !r.pandaCluster.Spec.ExternalConnectivity.Enabled {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/resources/service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewServiceAccount(

// Ensure manages ServiceAccount that is used in initContainer
func (s *ServiceAccountResource) Ensure(ctx context.Context) error {
if !s.pandaCluster.Spec.ExternalConnectivity {
if !s.pandaCluster.Spec.ExternalConnectivity.Enabled {
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/resources/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewStatefulSet(
func (r *StatefulSetResource) Ensure(ctx context.Context) error {
var sts appsv1.StatefulSet

if r.pandaCluster.Spec.ExternalConnectivity {
if r.pandaCluster.Spec.ExternalConnectivity.Enabled {
err := r.Get(ctx, r.nodePortName, &r.nodePortSvc)
if err != nil {
return fmt.Errorf("failed to retrieve node port service %s: %w", r.nodePortName, err)
Expand Down Expand Up @@ -289,7 +289,7 @@ func (r *StatefulSetResource) obj() (k8sclient.Object, error) {
},
{
Name: "EXTERNAL_CONNECTIVITY",
Value: strconv.FormatBool(r.pandaCluster.Spec.ExternalConnectivity),
Value: strconv.FormatBool(r.pandaCluster.Spec.ExternalConnectivity.Enabled),
},
{
Name: "HOST_PORT",
Expand Down Expand Up @@ -493,14 +493,14 @@ func (r *StatefulSetResource) secretVolumes() []corev1.Volume {
}

func (r *StatefulSetResource) getNodePort() string {
if r.pandaCluster.Spec.ExternalConnectivity {
if r.pandaCluster.Spec.ExternalConnectivity.Enabled {
return strconv.FormatInt(int64(r.nodePortSvc.Spec.Ports[0].NodePort), 10)
}
return ""
}

func (r *StatefulSetResource) getServiceAccountName() string {
if r.pandaCluster.Spec.ExternalConnectivity {
if r.pandaCluster.Spec.ExternalConnectivity.Enabled {
return r.serviceAccountName
}
return ""
Expand All @@ -522,7 +522,7 @@ func (r *StatefulSetResource) portsConfiguration() string {
}

func (r *StatefulSetResource) getPorts() []corev1.ContainerPort {
if r.pandaCluster.Spec.ExternalConnectivity &&
if r.pandaCluster.Spec.ExternalConnectivity.Enabled &&
len(r.nodePortSvc.Spec.Ports) > 0 {
return []corev1.ContainerPort{
{
Expand Down

0 comments on commit 7547e68

Please sign in to comment.