Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix api service reg #1337

Merged
merged 17 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ jobs:
-f ${{ matrix.test-suite-path }}/values.yaml \
"${extraArgs[@]}"
continue-on-error: true

- name: Install metrics server in host cluster
id: install-metrics-server
run: |-
set -x
helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
helm upgrade --install metrics-server metrics-server/metrics-server --set args={--kubelet-insecure-tls} --set containerPort=4443 -n kube-system

- name: Wait until vcluster is ready
id: wait-until-vcluster-is-ready
Expand Down
2 changes: 1 addition & 1 deletion charts/eks/templates/syncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ spec:
{{- if not .Values.syncer.noArgs }}
args:
- --name={{ .Release.Name }}
- --request-header-ca-cert=/pki/ca.crt
- --request-header-ca-cert=/pki/front-proxy-ca.crt
- --client-ca-cert=/pki/ca.crt
- --server-ca-cert=/pki/ca.crt
- --server-ca-key=/pki/ca.key
Expand Down
2 changes: 1 addition & 1 deletion charts/k8s/templates/syncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ spec:
{{- if not .Values.syncer.noArgs }}
args:
- --name={{ .Release.Name }}
- --request-header-ca-cert=/pki/ca.crt
- --request-header-ca-cert=/pki/front-proxy-ca.crt
- --client-ca-cert=/pki/ca.crt
- --server-ca-cert=/pki/ca.crt
- --server-ca-key=/pki/ca.key
Expand Down
6 changes: 6 additions & 0 deletions devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ deployments:
disabled: "false"
instanceCreatorType: "devspace"
instanceCreatorUID: "devspace"
proxy:
metricsServer:
nodes:
enabled: true
pods:
enabled: true
sync:
generic:
clusterRole:
Expand Down
100 changes: 99 additions & 1 deletion pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/loft-sh/vcluster/pkg/setup/options"

"github.com/loft-sh/vcluster/pkg/specialservices"
"github.com/loft-sh/vcluster/pkg/util/loghelper"
corev1 "k8s.io/api/core/v1"
discoveryv1 "k8s.io/api/discovery/v1"
Expand Down Expand Up @@ -40,6 +41,8 @@ type EndpointController struct {
Log loghelper.Logger

provider provider

k8sDistro bool
}

func NewEndpointController(ctx *options.ControllerContext, provider provider) *EndpointController {
Expand All @@ -51,6 +54,7 @@ func NewEndpointController(ctx *options.ControllerContext, provider provider) *E
VirtualManagerCache: ctx.VirtualManager.GetCache(),
Log: loghelper.New("kubernetes-default-endpoint-controller"),
provider: provider,
k8sDistro: ctx.Options.IsK8sDistro,
}
}

Expand All @@ -67,6 +71,13 @@ func (e *EndpointController) Reconcile(ctx context.Context, _ ctrl.Request) (ctr
if err != nil {
return ctrl.Result{RequeueAfter: time.Second}, err
}

if e.k8sDistro {
err = e.syncMetricsServerEndpoints(ctx, e.VirtualClient, e.LocalClient, e.ServiceName, e.ServiceNamespace)
if err != nil {
return ctrl.Result{RequeueAfter: time.Second}, err
}
}
return ctrl.Result{}, nil
}

Expand All @@ -79,7 +90,18 @@ func (e *EndpointController) SetupWithManager(mgr ctrl.Manager) error {
pfuncs := predicate.NewPredicateFuncs(pp)

vp := func(object client.Object) bool {
return object.GetNamespace() == "default" && object.GetName() == "kubernetes"
if object.GetNamespace() == specialservices.DefaultKubernetesSvcKey.Namespace && object.GetName() == specialservices.DefaultKubernetesSvcKey.Name {
return true
}

if e.k8sDistro {
if object.GetNamespace() == specialservices.VclusterProxyMetricsSvcKey.Namespace &&
object.GetName() == specialservices.VclusterProxyMetricsSvcKey.Name {
return true
}
}

return false
}
vfuncs := predicate.NewPredicateFuncs(vp)

Expand All @@ -94,6 +116,82 @@ func (e *EndpointController) SetupWithManager(mgr ctrl.Manager) error {
Complete(e)
}

func (e *EndpointController) syncMetricsServerEndpoints(ctx context.Context, virtualClient, localClient client.Client, serviceName, serviceNamespace string) error {
// get physical service endpoints
pEndpoints := &corev1.Endpoints{}
err := localClient.Get(ctx, types.NamespacedName{
Namespace: serviceNamespace,
Name: serviceName,
}, pEndpoints)
if err != nil {
if kerrors.IsNotFound(err) {
return nil
}

return err
}

vEndpoints := &corev1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Namespace: specialservices.VclusterProxyMetricsSvcKey.Namespace,
Name: specialservices.VclusterProxyMetricsSvcKey.Name,
},
}

result, err := controllerutil.CreateOrPatch(ctx, virtualClient, vEndpoints, func() error {
if vEndpoints.Labels == nil {
vEndpoints.Labels = map[string]string{}
}
// vEndpoints.Labels[discoveryv1.LabelSkipMirror] = "true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented out?


// build new subsets
newSubsets := []corev1.EndpointSubset{}
for _, subset := range pEndpoints.Subsets {
newPorts := []corev1.EndpointPort{}
for _, p := range subset.Ports {
if p.Name != "https" {
continue
}

newPorts = append(newPorts, p)
}

newAddresses := []corev1.EndpointAddress{}
for _, address := range subset.Addresses {
address.Hostname = ""
address.NodeName = nil
address.TargetRef = nil
newAddresses = append(newAddresses, address)
}
newNotReadyAddresses := []corev1.EndpointAddress{}
for _, address := range subset.NotReadyAddresses {
address.Hostname = ""
address.NodeName = nil
address.TargetRef = nil
newNotReadyAddresses = append(newNotReadyAddresses, address)
}

newSubsets = append(newSubsets, corev1.EndpointSubset{
Addresses: newAddresses,
NotReadyAddresses: newNotReadyAddresses,
Ports: newPorts,
})
}

vEndpoints.Subsets = newSubsets
return nil
})
if err != nil {
return nil
}

if result == controllerutil.OperationResultCreated || result == controllerutil.OperationResultUpdated {
return e.provider.createOrPatch(ctx, virtualClient, vEndpoints)
}

return err
}

func (e *EndpointController) syncKubernetesServiceEndpoints(ctx context.Context, virtualClient client.Client, localClient client.Client, serviceName, serviceNamespace string) error {
// get physical service endpoints
pEndpoints := &corev1.Endpoints{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/resources/endpoints/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (s *endpointsSyncer) Sync(ctx *synccontext.SyncContext, pObj client.Object,
var _ syncer.Starter = &endpointsSyncer{}

func (s *endpointsSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.Request) (bool, error) {
if req.Namespace == "default" && req.Name == "kubernetes" {
if req.NamespacedName == specialservices.DefaultKubernetesSvcKey {
return true, nil
} else if _, ok := specialservices.Default.SpecialServicesToSync()[req.NamespacedName]; ok {
ishankhare07 marked this conversation as resolved.
Show resolved Hide resolved
return true, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/controllers/resources/pods/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
podtranslate "github.com/loft-sh/vcluster/pkg/controllers/resources/pods/translate"
synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
generictesting "github.com/loft-sh/vcluster/pkg/controllers/syncer/testing"
"github.com/loft-sh/vcluster/pkg/setup/options"
"github.com/loft-sh/vcluster/pkg/specialservices"
"github.com/loft-sh/vcluster/pkg/util/maps"
"github.com/loft-sh/vcluster/pkg/util/translate"
"gotest.tools/assert"
Expand All @@ -21,6 +23,8 @@ import (
func TestSync(t *testing.T) {
translate.Default = translate.NewSingleNamespaceTranslator(generictesting.DefaultTestTargetNamespace)

specialservices.SetDefault(&options.VirtualClusterOptions{})

PodLogsVolumeName := "pod-logs"
LogsVolumeName := "logs"
KubeletPodVolumeName := "kubelet-pods"
Expand Down
Loading
Loading