Skip to content

Commit

Permalink
modify special service default setup and remove env var
Browse files Browse the repository at this point in the history
Signed-off-by: Ishan Khare <[email protected]>
  • Loading branch information
ishankhare07 committed Nov 9, 2023
1 parent c98aba1 commit eecb935
Show file tree
Hide file tree
Showing 22 changed files with 2,881 additions and 18 deletions.
4 changes: 0 additions & 4 deletions charts/eks/templates/syncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,6 @@ spec:
{{- end }}
- name: VCLUSTER_TELEMETRY_CONFIG
value: {{ .Values.telemetry | toJson | quote }}
{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }}
- name: SINGLE_BINARY_DISTRO
value: "false"
{{- end }}
volumeMounts:
- name: helm-cache
mountPath: /.cache/helm
Expand Down
4 changes: 0 additions & 4 deletions charts/k8s/templates/syncer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,6 @@ spec:
{{- end }}
- name: VCLUSTER_TELEMETRY_CONFIG
value: {{ .Values.telemetry | toJson | quote }}
{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }}
- name: SINGLE_BINARY_DISTRO
value: "false"
{{- end }}
volumeMounts:
- name: helm-cache
mountPath: /.cache/helm
Expand Down
1 change: 0 additions & 1 deletion pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (e *EndpointController) Reconcile(ctx context.Context, _ ctrl.Request) (ctr
return ctrl.Result{RequeueAfter: time.Second}, err
}

// TODO: Change this to only be set for k8s/eks distros and when using metrics proxy
if !e.singleBinaryDistro {
err = e.syncMetricsServerEndpoints(ctx, e.VirtualClient, e.LocalClient, e.ServiceName, e.ServiceNamespace)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions pkg/server/cert/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"net"
"os"

"github.com/loft-sh/vcluster/pkg/specialservices"
"github.com/loft-sh/vcluster/pkg/util/certhelper"
"k8s.io/apimachinery/pkg/util/sets"
)

func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byte, clusterDomain string, SANs []string) ([]byte, []byte, bool, error) {
func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byte, clusterDomain string, SANs []string, isSingleBinaryDistro bool) ([]byte, []byte, bool, error) {
regen := false
commonName := "kube-apiserver"
extKeyUsage := []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
Expand All @@ -25,7 +24,7 @@ func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byt
"localhost",
}

if isSingleBinaryDistro := os.Getenv(specialservices.DistroEnvKey); isSingleBinaryDistro == "false" {
if !isSingleBinaryDistro {
dnsNames = append(dnsNames, []string{
"metrics-server.kube-system.svc." + clusterDomain,
"metrics-server.kube-system.svc",
Expand Down
6 changes: 5 additions & 1 deletion pkg/server/cert/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func NewSyncer(_ context.Context, currentNamespace string, currentNamespaceClien
serviceName: options.ServiceName,
currentNamespace: currentNamespace,
currentNamespaceCient: currentNamespaceClient,

isSingleBinaryDistro: options.SingleBinaryDistro,
}, nil
}

Expand All @@ -67,6 +69,8 @@ type syncer struct {
currentCert []byte
currentKey []byte
currentSANs []string

isSingleBinaryDistro bool
}

func (s *syncer) Name() string {
Expand Down Expand Up @@ -195,7 +199,7 @@ func (s *syncer) regen(extraSANs []string) error {
klog.Infof("Generating serving cert for service ips: %v", extraSANs)

// GenServingCerts will write generated or updated cert/key to s.currentCert, s.currentKey
cert, key, _, err := GenServingCerts(s.serverCaCert, s.serverCaKey, s.currentCert, s.currentKey, s.clusterDomain, extraSANs)
cert, key, _, err := GenServingCerts(s.serverCaCert, s.serverCaKey, s.currentCert, s.currentKey, s.clusterDomain, extraSANs, s.isSingleBinaryDistro)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/setup/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/loft-sh/vcluster/pkg/certs"
"github.com/loft-sh/vcluster/pkg/k3s"
"github.com/loft-sh/vcluster/pkg/setup/options"
"github.com/loft-sh/vcluster/pkg/specialservices"
"github.com/loft-sh/vcluster/pkg/util/servicecidr"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -57,6 +58,8 @@ func Initialize(
return err
}

specialservices.SetDefault(options)

return nil
}

Expand Down
13 changes: 8 additions & 5 deletions pkg/specialservices/resolver.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package specialservices

import (
"os"

synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context"
"github.com/loft-sh/vcluster/pkg/setup/options"
"github.com/loft-sh/vcluster/pkg/util/translate"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var Default = DefaultNameserverFinder()
var Default Interface

func SetDefault(ctrlCtx *options.VirtualClusterOptions) {
Default = defaultNameserverFinder(ctrlCtx.SingleBinaryDistro)
}

const (
DefaultKubeDNSServiceName = "kube-dns"
Expand Down Expand Up @@ -43,12 +46,12 @@ func (f *NameserverFinder) SpecialServicesToSync() map[types.NamespacedName]Spec
return f.SpecialServices
}

func DefaultNameserverFinder() Interface {
func defaultNameserverFinder(isSingleBinaryDistro bool) Interface {
specialServicesMap := map[types.NamespacedName]SpecialServiceSyncer{
DefaultKubernetesSvcKey: SyncKubernetesService,
}

if isSingleBinaryDistro := os.Getenv(DistroEnvKey); isSingleBinaryDistro == "false" {
if !isSingleBinaryDistro {
specialServicesMap[VclusterProxyMetricsSvcKey] = SyncVclusterProxyService
}

Expand Down
24 changes: 24 additions & 0 deletions vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit eecb935

Please sign in to comment.