Skip to content

Commit

Permalink
enable mcs to support headless-svc
Browse files Browse the repository at this point in the history
Signed-off-by: wenche <wenchuan.zhao@qq.com>
  • Loading branch information
WenchuanZhao committed Apr 11, 2023
1 parent 7589eae commit 313065f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/controllers/mcs/endpointslice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
mcsv1alpha1 "sigs.k8s.io/mcs-api/pkg/apis/v1alpha1"

workv1alpha1 "github.com/karmada-io/karmada/pkg/apis/work/v1alpha1"
"github.com/karmada-io/karmada/pkg/util"
Expand Down Expand Up @@ -103,6 +104,7 @@ func (c *EndpointSliceController) collectEndpointSliceFromWork(work *workv1alpha
workv1alpha1.WorkNamespaceLabel: work.Namespace,
workv1alpha1.WorkNameLabel: work.Name,
discoveryv1.LabelServiceName: names.GenerateDerivedServiceName(work.Labels[util.ServiceNameLabel]),
mcsv1alpha1.LabelServiceName: work.Labels[util.ServiceNameLabel],
}

if err = helper.CreateOrUpdateEndpointSlice(c.Client, desiredEndpointSlice); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/controllers/mcs/service_import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *ServiceImportController) Reconcile(ctx context.Context, req controllerr
return controllerruntime.Result{Requeue: true}, err
}

if !svcImport.DeletionTimestamp.IsZero() || svcImport.Spec.Type != mcsv1alpha1.ClusterSetIP {
if !svcImport.DeletionTimestamp.IsZero() {
return controllerruntime.Result{}, nil
}

Expand Down Expand Up @@ -93,6 +93,10 @@ func (c *ServiceImportController) deriveServiceFromServiceImport(svcImport *mcsv
},
}

if svcImport.Spec.Type == mcsv1alpha1.Headless {
newDerivedService.Spec.ClusterIP = corev1.ClusterIPNone
}

oldDerivedService := &corev1.Service{}
err := c.Client.Get(context.TODO(), types.NamespacedName{
Name: names.GenerateDerivedServiceName(svcImport.Name),
Expand Down

0 comments on commit 313065f

Please sign in to comment.