Skip to content

Commit

Permalink
Create single dervice to dataplane pod
Browse files Browse the repository at this point in the history
Signed-off-by: Kfir Toledo <kfir.toledo@ibm.com>
  • Loading branch information
kfirtoledo committed Jun 26, 2024
1 parent f8d37e9 commit c8de7e2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 30 deletions.
2 changes: 2 additions & 0 deletions cmd/cl-dataplane/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (

// Name is the app label of dataplane pods.
Name = "cl-dataplane"
// IngressSvcName is the ingress service name for the dataplane pods.
IngressSvcName = "cl-dataplane"
)

// Options contains everything necessary to create and run a dataplane.
Expand Down
24 changes: 8 additions & 16 deletions pkg/bootstrap/platform/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
apis "github.com/clusterlink-net/clusterlink/pkg/apis/clusterlink.net/v1alpha1"
cpapi "github.com/clusterlink-net/clusterlink/pkg/controlplane/api"
dpapi "github.com/clusterlink-net/clusterlink/pkg/dataplane/api"
corev1 "k8s.io/api/core/v1"
)

const (
Expand Down Expand Up @@ -186,18 +187,6 @@ spec:
- name: controlplane
port: {{.controlplanePort}}
---
apiVersion: v1
kind: Service
metadata:
name: cl-dataplane
namespace: {{.namespace}}
spec:
selector:
app: {{ .dataplaneAppName }}
ports:
- name: dataplane
port: {{.dataplanePort}}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand Down Expand Up @@ -273,7 +262,7 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: clusterlink
name: {{.dataplaneService}}
namespace: {{.namespace}}
spec:
type: {{.ingressType}}
Expand Down Expand Up @@ -450,15 +439,18 @@ func K8SEmptyCertificateConfig(config *Config) ([]byte, error) {
// k8SIngressConfig returns a kubernetes ingress service.
func k8SIngressConfig(config *Config) ([]byte, error) {
var ingressConfig bytes.Buffer
if config.IngressType == "" {
return ingressConfig.Bytes(), nil

ingressType := string(corev1.ServiceTypeClusterIP)
if config.IngressType == string(apis.IngressTypeNodePort) || config.IngressType == string(apis.IngressTypeLoadBalancer) {
ingressType = config.IngressType
}

args := map[string]interface{}{
"namespace": config.Namespace,
"ingressPort": apis.DefaultExternalPort,
"ingressType": config.IngressType,
"ingressType": ingressType,

"dataplaneService": dpapp.IngressSvcName,
"dataplaneAppName": dpapp.Name,
"dataplanePort": dpapi.ListenPort,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controlplane/control/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ func (m *Manager) addImportEndpointSlices(ctx context.Context, imp *v1alpha1.Imp
err := m.client.List(
ctx,
&dataplaneEndpointSliceList,
client.MatchingLabels{discv1.LabelServiceName: dpapp.Name},
client.MatchingLabels{discv1.LabelServiceName: dpapp.IngressSvcName},
client.InNamespace(m.namespace))
if err != nil {
return err
Expand Down
11 changes: 3 additions & 8 deletions pkg/operator/controller/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
ControlPlaneName = "cl-controlplane"
DataPlaneName = "cl-dataplane"
GoDataPlaneName = "cl-go-dataplane"
IngressName = "clusterlink"
OperatorNamespace = "clusterlink-operator"
InstanceNamespace = "clusterlink-system"
FinalizerName = "instance.clusterlink.net/finalizer"
Expand Down Expand Up @@ -204,10 +203,6 @@ func (r *InstanceReconciler) applyClusterLink(ctx context.Context, instance *clu
}

// Create datapalne components
if err := r.createService(ctx, DataPlaneName, instance.Spec.Namespace, dpapi.ListenPort); err != nil {
return err
}

if err := r.applyDataplane(ctx, instance); err != nil {
return err
}
Expand Down Expand Up @@ -516,7 +511,7 @@ func (r *InstanceReconciler) createExternalService(ctx context.Context, instance
// Create a Service object
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: IngressName,
Name: dpapp.IngressSvcName,
Namespace: instance.Spec.Namespace,
Annotations: instance.Spec.Ingress.Annotations,
},
Expand Down Expand Up @@ -632,7 +627,7 @@ func (r *InstanceReconciler) deleteClusterLink(ctx context.Context, namespace st
}

// Delete external ingress service
ingerssObj := metav1.ObjectMeta{Name: IngressName, Namespace: namespace}
ingerssObj := metav1.ObjectMeta{Name: dpapp.IngressSvcName, Namespace: namespace}
return r.deleteResource(ctx, &corev1.Service{ObjectMeta: ingerssObj})
}

Expand Down Expand Up @@ -720,7 +715,7 @@ func (r *InstanceReconciler) checkDataplaneStatus(ctx context.Context, instance

// checkIngressStatus check the status of the ingress components.
func (r *InstanceReconciler) checkIngressStatus(ctx context.Context, instance *clusterlink.Instance) (bool, error) {
ingress := types.NamespacedName{Name: IngressName, Namespace: instance.Spec.Namespace}
ingress := types.NamespacedName{Name: dpapp.IngressSvcName, Namespace: instance.Spec.Namespace}
serviceStatus, err := r.checkExternalServiceStatus(ctx, ingress, &instance.Status.Ingress)
if err != nil {
return false, err
Expand Down
5 changes: 3 additions & 2 deletions pkg/operator/controller/instance_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"

dpapp "github.com/clusterlink-net/clusterlink/cmd/cl-dataplane/app"
clusterlink "github.com/clusterlink-net/clusterlink/pkg/apis/clusterlink.net/v1alpha1"
"github.com/clusterlink-net/clusterlink/pkg/operator/controller"
)
Expand Down Expand Up @@ -150,8 +151,8 @@ func TestClusterLinkController(t *testing.T) {
}
roleResource := []client.Object{&rbacv1.ClusterRole{}, &rbacv1.ClusterRoleBinding{}}
dpID := types.NamespacedName{Name: controller.DataPlaneName, Namespace: controller.InstanceNamespace}
dpResource := []client.Object{&appsv1.Deployment{}, &corev1.Service{}}
ingressID := types.NamespacedName{Name: controller.IngressName, Namespace: controller.InstanceNamespace}
dpResource := []client.Object{&appsv1.Deployment{}}
ingressID := types.NamespacedName{Name: dpapp.IngressSvcName, Namespace: controller.InstanceNamespace}

t.Run("Create ClusterLink deployment", func(t *testing.T) {
// Create ClusterLink namespaces
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/k8s/test_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

dpapp "github.com/clusterlink-net/clusterlink/cmd/cl-dataplane/app"
"github.com/clusterlink-net/clusterlink/pkg/apis/clusterlink.net/v1alpha1"
"github.com/clusterlink-net/clusterlink/pkg/controlplane/control"
"github.com/clusterlink-net/clusterlink/tests/e2e/k8s/services"
Expand Down Expand Up @@ -407,7 +408,7 @@ func (s *TestSuite) TestImportMerge() {
// delete dataplane endpoint slice by deleting the dataplane service
var dataplaneService v1.Service
require.Nil(s.T(), cl[0].Cluster().Resources().Get(
context.Background(), "cl-dataplane", cl[0].Namespace(), &dataplaneService))
context.Background(), dpapp.IngressSvcName, cl[0].Namespace(), &dataplaneService))
require.Nil(s.T(), cl[0].Cluster().Resources().Delete(
context.Background(), &dataplaneService))

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/k8s/util/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/klient/wait/conditions"

dpapp "github.com/clusterlink-net/clusterlink/cmd/cl-dataplane/app"
"github.com/clusterlink-net/clusterlink/cmd/clusterlink/config"
"github.com/clusterlink-net/clusterlink/pkg/apis/clusterlink.net/v1alpha1"
"github.com/clusterlink-net/clusterlink/pkg/bootstrap"
Expand Down Expand Up @@ -258,9 +259,8 @@ func (f *Fabric) deployClusterLink(target *peer, cfg *PeerConfig) (*ClusterLink,
return nil, fmt.Errorf("namespace not set")
}

svcNodePort := "cl-dataplane"
svcNodePort := dpapp.IngressSvcName
if cfg.DeployWithOperator {
svcNodePort = controller.IngressName
deployFunc = f.deployUsingOperator
} else {
deployFunc = f.deployUsingK8sYAML
Expand Down

0 comments on commit c8de7e2

Please sign in to comment.