From 895e546d8cbd26904459b4e6a6f0cce19bfe47b5 Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Thu, 26 Oct 2023 10:39:48 +0200 Subject: [PATCH 01/17] fix: allow custom k3s token --- charts/k3s/values.yaml | 3 +++ devspace.yaml | 4 ++++ pkg/metricsapiservice/register.go | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/charts/k3s/values.yaml b/charts/k3s/values.yaml index b16b8ce5b..69a7aa5d1 100644 --- a/charts/k3s/values.yaml +++ b/charts/k3s/values.yaml @@ -267,6 +267,9 @@ podAnnotations: {} # The k3s token to use. If empty will generate one automatically k3sToken: "" +# The k3s token to use. If empty will generate one automatically +k3sToken: "" + # Service configurations service: type: ClusterIP diff --git a/devspace.yaml b/devspace.yaml index 98d95b661..d04695151 100644 --- a/devspace.yaml +++ b/devspace.yaml @@ -136,6 +136,10 @@ pipelines: # Deploy the vcluster if is_equal $(get_flag distro) k8s; then +<<<<<<< HEAD +======= + kubectl apply -f ./hack/vcluster-certs.yaml -n ${DEVSPACE_NAMESPACE} +>>>>>>> 1e206c68 (fix: allow custom k3s token) create_deployments vcluster-k8s elif is_equal $(get_flag distro) k0s; then create_deployments vcluster-k0s diff --git a/pkg/metricsapiservice/register.go b/pkg/metricsapiservice/register.go index af17453ab..3f4496fba 100644 --- a/pkg/metricsapiservice/register.go +++ b/pkg/metricsapiservice/register.go @@ -5,6 +5,7 @@ import ( "math" "time" + vclustercontext "github.com/loft-sh/vcluster/cmd/vcluster/context" "github.com/loft-sh/vcluster/pkg/setup/options" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -72,6 +73,10 @@ func deleteOperation(_ context.Context, client client.Client) wait.ConditionWith } func createOperation(_ context.Context, client client.Client) wait.ConditionWithContextFunc { + // first check if we are in k8s or eks distro mode where + // syncer and api server are behind separate services + // checkForSeparateAPIServerService() + return func(ctx context.Context) (bool, error) { spec := apiregistrationv1.APIServiceSpec{ Group: metrics.GroupName, @@ -114,3 +119,6 @@ func RegisterOrDeregisterAPIService(ctx context.Context, options *options.Virtua return nil } + +func checkForSeparateAPIServerService(ctx context.Context, options *vclustercontext.VirtualClusterOptions) { +} From 729b8b93a3323616d149f6c62d4010eecdebda44 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Fri, 29 Sep 2023 20:39:01 +0530 Subject: [PATCH 02/17] aux metrics proxy svc Signed-off-by: Ishan Khare --- aux-vcluster-metrics-svc.yaml | 28 +++++++ .../k8s/templates/proxy-metrics-server.yaml | 25 +++++++ charts/k8s/templates/syncer-deployment.yaml | 2 +- devspace.yaml | 10 ++- in-vcluster-metrics-svc.yaml | 17 +++++ .../k8sdefaultendpoint/k8sdefaultendpoint.go | 8 +- pkg/controllers/resources/endpoints/syncer.go | 7 +- pkg/controllers/resources/services/syncer.go | 6 +- pkg/metricsapiservice/register.go | 24 +++--- pkg/server/cert/cert.go | 14 +++- pkg/specialservices/proxy_service_syncer.go | 73 +++++++++++++++++++ pkg/specialservices/resolver.go | 6 +- pkg/specialservices/service_syncer.go | 7 ++ 13 files changed, 201 insertions(+), 26 deletions(-) create mode 100644 aux-vcluster-metrics-svc.yaml create mode 100644 charts/k8s/templates/proxy-metrics-server.yaml create mode 100644 in-vcluster-metrics-svc.yaml create mode 100644 pkg/specialservices/proxy_service_syncer.go diff --git a/aux-vcluster-metrics-svc.yaml b/aux-vcluster-metrics-svc.yaml new file mode 100644 index 000000000..2f89adc3d --- /dev/null +++ b/aux-vcluster-metrics-svc.yaml @@ -0,0 +1,28 @@ +apiVersion: v1 +kind: Service +metadata: + name: vcluster-metrics-proxy + namespace: vcluster + labels: + app: vcluster + chart: vcluster-k8s-0.0.1 + release: vcluter + heritage: helm + annotations: + meta.helm.sh/release-name: vcluster + meta.helm.sh/release-namespace: vcluster +spec: + type: NodePort + ports: + - name: https + port: 443 + targetPort: 8443 + protocol: TCP + - name: kubelet + port: 10250 + targetPort: 8443 + protocol: TCP + externalTrafficPolicy: Cluster + selector: + app: vcluster + release: vcluster \ No newline at end of file diff --git a/charts/k8s/templates/proxy-metrics-server.yaml b/charts/k8s/templates/proxy-metrics-server.yaml new file mode 100644 index 000000000..b1ca8c099 --- /dev/null +++ b/charts/k8s/templates/proxy-metrics-server.yaml @@ -0,0 +1,25 @@ +{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-metrics-server + namespace: {{ .Release.Namespace }} +data: + metrics-server.yaml: |- + apiVersion: v1 + kind: Service + metadata: + labels: + k8s-app: metrics-server + name: metrics-server + namespace: kube-system + spec: + - name: https + port: 443 + protocol: TCP + targetPort: https + selector: + k8s-app: metrics-server + sessionAffinity: None + type: ClusterIP +{{- end }} \ No newline at end of file diff --git a/charts/k8s/templates/syncer-deployment.yaml b/charts/k8s/templates/syncer-deployment.yaml index 51306ca76..721f7e631 100644 --- a/charts/k8s/templates/syncer-deployment.yaml +++ b/charts/k8s/templates/syncer-deployment.yaml @@ -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 diff --git a/devspace.yaml b/devspace.yaml index d04695151..4a1473688 100644 --- a/devspace.yaml +++ b/devspace.yaml @@ -52,6 +52,12 @@ deployments: disabled: "false" instanceCreatorType: "devspace" instanceCreatorUID: "devspace" + proxy: + metricsServer: + nodes: + enabled: true + pods: + enabled: true sync: generic: clusterRole: @@ -136,10 +142,6 @@ pipelines: # Deploy the vcluster if is_equal $(get_flag distro) k8s; then -<<<<<<< HEAD -======= - kubectl apply -f ./hack/vcluster-certs.yaml -n ${DEVSPACE_NAMESPACE} ->>>>>>> 1e206c68 (fix: allow custom k3s token) create_deployments vcluster-k8s elif is_equal $(get_flag distro) k0s; then create_deployments vcluster-k0s diff --git a/in-vcluster-metrics-svc.yaml b/in-vcluster-metrics-svc.yaml new file mode 100644 index 000000000..6e628cda6 --- /dev/null +++ b/in-vcluster-metrics-svc.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + labels: + k8s-app: metrics-server + name: metrics-server + namespace: kube-system +spec: + ports: + - name: https + port: 443 + protocol: TCP + targetPort: 8443 + selector: + k8s-app: metrics-server + sessionAffinity: None + type: ClusterIP \ No newline at end of file diff --git a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go index dfcb6b0bd..feb813416 100644 --- a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go +++ b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go @@ -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" @@ -79,7 +80,12 @@ 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 + } + + return false } vfuncs := predicate.NewPredicateFuncs(vp) diff --git a/pkg/controllers/resources/endpoints/syncer.go b/pkg/controllers/resources/endpoints/syncer.go index 6ae1fa006..606e3526f 100644 --- a/pkg/controllers/resources/endpoints/syncer.go +++ b/pkg/controllers/resources/endpoints/syncer.go @@ -40,12 +40,17 @@ 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 || + req.NamespacedName == specialservices.VclusterProxyMetricsSvcKey { return true, nil } else if _, ok := specialservices.Default.SpecialServicesToSync()[req.NamespacedName]; ok { return true, nil } + // if req.Namespace == "default" && req.Name == "kubernetes" { + // return true, nil + // } + svc := &corev1.Service{} err := ctx.VirtualClient.Get(ctx.Context, types.NamespacedName{ Namespace: req.Namespace, diff --git a/pkg/controllers/resources/services/syncer.go b/pkg/controllers/resources/services/syncer.go index 986f24c2c..2cbcb8357 100644 --- a/pkg/controllers/resources/services/syncer.go +++ b/pkg/controllers/resources/services/syncer.go @@ -157,8 +157,12 @@ var _ syncertypes.Starter = &serviceSyncer{} func (s *serviceSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.Request) (bool, error) { // don't do anything for the kubernetes service specialServices := specialservices.Default.SpecialServicesToSync() - if svc, ok := specialServices[req.NamespacedName]; ok { + + svc, ok := specialServices[req.NamespacedName] + if ok && req.NamespacedName == specialservices.DefaultKubernetesSvcKey { return true, svc(ctx, ctx.CurrentNamespace, s.serviceName, req.NamespacedName, TranslateServicePorts) + } else if ok && req.NamespacedName == specialservices.VclusterProxyMetricsSvcKey { + return true, svc(ctx, ctx.CurrentNamespace, s.serviceName+"-metrics-proxy", req.NamespacedName, func(p []corev1.ServicePort) []corev1.ServicePort { return []corev1.ServicePort{} }) } return false, nil diff --git a/pkg/metricsapiservice/register.go b/pkg/metricsapiservice/register.go index 3f4496fba..93b4a2d61 100644 --- a/pkg/metricsapiservice/register.go +++ b/pkg/metricsapiservice/register.go @@ -5,7 +5,6 @@ import ( "math" "time" - vclustercontext "github.com/loft-sh/vcluster/cmd/vcluster/context" "github.com/loft-sh/vcluster/pkg/setup/options" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -13,6 +12,7 @@ import ( "k8s.io/klog/v2" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" "k8s.io/metrics/pkg/apis/metrics" + "k8s.io/utils/pointer" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -73,16 +73,19 @@ func deleteOperation(_ context.Context, client client.Client) wait.ConditionWith } func createOperation(_ context.Context, client client.Client) wait.ConditionWithContextFunc { - // first check if we are in k8s or eks distro mode where - // syncer and api server are behind separate services - // checkForSeparateAPIServerService() - return func(ctx context.Context) (bool, error) { spec := apiregistrationv1.APIServiceSpec{ - Group: metrics.GroupName, - GroupPriorityMinimum: 100, - Version: MetricsVersion, - VersionPriority: 100, + Service: &apiregistrationv1.ServiceReference{ + Name: "metrics-server", + Namespace: "kube-system", + Port: pointer.Int32(443), + }, + Group: metrics.GroupName, + GroupPriorityMinimum: 100, + Version: MetricsVersion, + VersionPriority: 100, + InsecureSkipTLSVerify: true, + // CABundle: []byte(`-----BEGIN CERTIFICATE-----\nMIIC/jCCAeagAwIBAgIBADANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwprdWJl\ncm5ldGVzMB4XDTIyMDgxNjAzMDgwMFoXDTMyMDgxMzAzMDgwMFowFTETMBEGA1UE\nAxMKa3ViZXJuZXRlczCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMf1\nzJTnoUVt+OH4GG2qLFN4JlLoupTa3xFr+yhnJxf0LqVMBF6JKN/0khKEClFlO1lp\nXtWZHbz2yrQKB/3PZ7mWZiu5zcW4BxMFww6Je/2Ut5Y9KWcQgocdu9lQkhkCyPY9\no5RKVCEnuSB/rfYPD2d97Q4bNDwH6+/DT6vOE1KcNY7nzLynWcSa+xAh/ArG+PZO\noUIZ1kjDbE7NL7IJV1yWTvmVokOV9BDTll4HPctvhMblYMzZbxG6uB1SniJlxzuB\nF1+uBrVV/v5H4c4xyko5WTFwhAMe1aLM4NEpE6xCEoJmB6Qgrhun1AMukUBuJkqE\nxWykUfLkLK1lgFU2OdsCAwEAAaNZMFcwDgYDVR0PAQH/BAQDAgKkMA8GA1UdEwEB\n/wQFMAMBAf8wHQYDVR0OBBYEFHwYuwZ+21NrYghdBkY0HG9CkgfmMBUGA1UdEQQO\nMAyCCmt1YmVybmV0ZXMwDQYJKoZIhvcNAQELBQADggEBALgbrX/UUXSLi/uRZ5h7\nKMluBCBFs1ATBfgzlMHqlCdYJTR/Eps3NWBy26+yC0URYIlnDHqtQs14eHPo0iJR\nrff6BTQvyS5jZqkZyvkQWjE8J9xXVJe6vew8yQbM4pgZZIXjRRBjV7Mlr6bzjY74\nxxlI1JnCP75+/3sJnQrZDy6lcg4MsacvojHYdXEgHX8MccEZ6Gt6x2++plsfmtax\nFspo3R7HuP1eM4jlZ24rRj+w2bwyTPZ22wpc6eAljrR2qjlYWHEmTMKQS+MjJk5q\nzg2frjE410c8bqLZpa61Npun/q7gpxIAXlj914DJEiv+9DotjQuFJ59mQFYrU9iA\nfVE=\n-----END CERTIFICATE-----`), } apiService := &apiregistrationv1.APIService{ @@ -119,6 +122,3 @@ func RegisterOrDeregisterAPIService(ctx context.Context, options *options.Virtua return nil } - -func checkForSeparateAPIServerService(ctx context.Context, options *vclustercontext.VirtualClusterOptions) { -} diff --git a/pkg/server/cert/cert.go b/pkg/server/cert/cert.go index 4b6eaf318..69c04cb32 100644 --- a/pkg/server/cert/cert.go +++ b/pkg/server/cert/cert.go @@ -16,8 +16,18 @@ func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byt commonName := "kube-apiserver" extKeyUsage := []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth} altNames := &certhelper.AltNames{ - DNSNames: []string{"kubernetes.default.svc." + clusterDomain, "kubernetes.default.svc", "kubernetes.default", "kubernetes", "localhost"}, - IPs: []net.IP{net.ParseIP("127.0.0.1")}, + DNSNames: []string{ + "kubernetes.default.svc." + clusterDomain, + "kubernetes.default.svc", + "kubernetes.default", + "kubernetes", + "localhost", + "metrics-server.kube-system.svc." + clusterDomain, + "metrics-server.kube-system.svc", + "metrics-server.kube-system", + "metrics-server", + }, + IPs: []net.IP{net.ParseIP("127.0.0.1")}, } addSANs(altNames, SANs) diff --git a/pkg/specialservices/proxy_service_syncer.go b/pkg/specialservices/proxy_service_syncer.go new file mode 100644 index 000000000..39cde29f3 --- /dev/null +++ b/pkg/specialservices/proxy_service_syncer.go @@ -0,0 +1,73 @@ +package specialservices + +import ( + synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/equality" + kerrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/types" +) + +var ( + VclusterProxyMetricsSvcKey = types.NamespacedName{ + Name: "metrics-server", + Namespace: "kube-system", + } +) + +func SyncVclusterProxyService(ctx *synccontext.SyncContext, + svcNamespace, + svcName string, + vSvcToSync types.NamespacedName, + svcPortTranslator ServicePortTranslator) error { + + pClient := ctx.PhysicalClient + // get physical service + pObj := &corev1.Service{} + err := pClient.Get(ctx.Context, types.NamespacedName{ + Namespace: svcNamespace, + Name: svcName, + }, pObj) + + if err != nil { + if kerrors.IsNotFound(err) { + return nil + } + + return err + } + + vClient := ctx.VirtualClient + vObj := &corev1.Service{} + err = vClient.Get(ctx.Context, vSvcToSync, vObj) + if err != nil { + if kerrors.IsNotFound(err) { + return nil + } + + return err + } + + if vObj.Spec.ClusterIP != pObj.Spec.ClusterIP || !equality.Semantic.DeepEqual(vObj.Spec.ClusterIPs, pObj.Spec.ClusterIPs) { + newService := vObj.DeepCopy() + newService.Spec.ClusterIP = pObj.Spec.ClusterIP + newService.Spec.ClusterIPs = pObj.Spec.ClusterIPs + newService.Spec.IPFamilies = pObj.Spec.IPFamilies + + // delete & create with correct ClusterIP + err = vClient.Delete(ctx.Context, vObj) + if err != nil { + return err + } + + newService.ResourceVersion = "" + + // create the new service with the correct cluster ip + err = vClient.Create(ctx.Context, newService) + if err != nil { + return err + } + } + + return nil +} diff --git a/pkg/specialservices/resolver.go b/pkg/specialservices/resolver.go index 7f08691a9..e60685053 100644 --- a/pkg/specialservices/resolver.go +++ b/pkg/specialservices/resolver.go @@ -42,10 +42,8 @@ func (f *NameserverFinder) SpecialServicesToSync() map[types.NamespacedName]Spec func DefaultNameserverFinder() Interface { return &NameserverFinder{ SpecialServices: map[types.NamespacedName]SpecialServiceSyncer{ - { - Name: DefaultKubernetesSVCName, - Namespace: DefaultKubernetesSVCNamespace, - }: SyncKubernetesService, + DefaultKubernetesSvcKey: SyncKubernetesService, + VclusterProxyMetricsSvcKey: SyncVclusterProxyService, }, } } diff --git a/pkg/specialservices/service_syncer.go b/pkg/specialservices/service_syncer.go index c135387fe..9d28d1e45 100644 --- a/pkg/specialservices/service_syncer.go +++ b/pkg/specialservices/service_syncer.go @@ -9,6 +9,13 @@ import ( "k8s.io/apimachinery/pkg/types" ) +var ( + DefaultKubernetesSvcKey = types.NamespacedName{ + Name: DefaultKubernetesSVCName, + Namespace: DefaultKubernetesSVCNamespace, + } +) + const ( DefaultKubernetesSVCName = "kubernetes" DefaultKubernetesSVCNamespace = "default" From acf2680dde5fcc3d08bfbe16c084b63668996df6 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 31 Oct 2023 16:59:26 +0530 Subject: [PATCH 03/17] sync endpoints and detect single binary distros Signed-off-by: Ishan Khare --- aux-vcluster-metrics-svc.yaml | 28 ------ charts/k8s/templates/metrics-proxy.yaml | 59 +++++++++++++ charts/k8s/templates/syncer-deployment.yaml | 14 +++ in-vcluster-metrics-svc.yaml | 17 ---- .../k8sdefaultendpoint/k8sdefaultendpoint.go | 87 +++++++++++++++++++ pkg/controllers/resources/endpoints/syncer.go | 9 +- pkg/controllers/resources/services/syncer.go | 4 +- pkg/metricsapiservice/register.go | 50 ++++++++--- pkg/setup/controllers.go | 3 +- pkg/setup/options/flags.go | 1 + pkg/setup/options/options.go | 2 + pkg/specialservices/proxy_service_syncer.go | 28 +++++- pkg/specialservices/resolver.go | 17 +++- 13 files changed, 242 insertions(+), 77 deletions(-) delete mode 100644 aux-vcluster-metrics-svc.yaml create mode 100644 charts/k8s/templates/metrics-proxy.yaml delete mode 100644 in-vcluster-metrics-svc.yaml diff --git a/aux-vcluster-metrics-svc.yaml b/aux-vcluster-metrics-svc.yaml deleted file mode 100644 index 2f89adc3d..000000000 --- a/aux-vcluster-metrics-svc.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: vcluster-metrics-proxy - namespace: vcluster - labels: - app: vcluster - chart: vcluster-k8s-0.0.1 - release: vcluter - heritage: helm - annotations: - meta.helm.sh/release-name: vcluster - meta.helm.sh/release-namespace: vcluster -spec: - type: NodePort - ports: - - name: https - port: 443 - targetPort: 8443 - protocol: TCP - - name: kubelet - port: 10250 - targetPort: 8443 - protocol: TCP - externalTrafficPolicy: Cluster - selector: - app: vcluster - release: vcluster \ No newline at end of file diff --git a/charts/k8s/templates/metrics-proxy.yaml b/charts/k8s/templates/metrics-proxy.yaml new file mode 100644 index 000000000..41ae37c2e --- /dev/null +++ b/charts/k8s/templates/metrics-proxy.yaml @@ -0,0 +1,59 @@ +{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-metrics-proxy + namespace: {{ .Release.Namespace }} + labels: + app: vcluster-metrics-proxy + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + {{- $annotations := merge .Values.globalAnnotations .Values.syncer.serviceAnnotations }} + {{- if $annotations }} + annotations: +{{ toYaml $annotations | indent 4 }} + {{- end }} +spec: + ports: + - name: https + port: 443 + targetPort: 8443 + protocol: TCP + - name: kubelet + port: 10250 + targetPort: 8443 + protocol: TCP + selector: + app: vcluster + release: {{ .Release.Name }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-metrics-proxy + namespace: {{ .Release.Namespace }} + {{- if .Values.globalAnnotations }} + annotations: +{{ toYaml .Values.globalAnnotations | indent 4 }} + {{- end }} +data: + service.yaml: |- + apiVersion: v1 + kind: Service + metadata: + labels: + k8s-app: metrics-server + name: metrics-server + namespace: kube-system + spec: + ports: + - name: https + port: 443 + protocol: TCP + targetPort: 8443 + selector: + k8s-app: metrics-server + sessionAffinity: None + type: ClusterIP +{{- end }} \ No newline at end of file diff --git a/charts/k8s/templates/syncer-deployment.yaml b/charts/k8s/templates/syncer-deployment.yaml index 721f7e631..888aa761b 100644 --- a/charts/k8s/templates/syncer-deployment.yaml +++ b/charts/k8s/templates/syncer-deployment.yaml @@ -122,6 +122,11 @@ spec: configMap: name: coredns-custom optional: true + {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} + - name: metrics-proxy-svc + configMap: + name: {{ .Release.Name }}-metrics-proxy + {{- end }} {{- if .Values.syncer.priorityClassName }} priorityClassName: {{ .Values.syncer.priorityClassName }} {{- end }} @@ -202,6 +207,7 @@ spec: {{- end }} {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} - --proxy-metrics-server=true + - --single-binary-distro=false {{- end }} {{- if .Values.coredns.integrated }} - --integrated-coredns=true @@ -261,6 +267,10 @@ 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 @@ -273,6 +283,10 @@ spec: mountPath: /manifests/coredns readOnly: true {{- end }} + {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} + - name: metrics-proxy-svc + mountPath: /manifests/metrics-server + {{- end }} {{- if .Values.syncer.volumeMounts }} {{ toYaml .Values.syncer.volumeMounts | indent 10 }} {{- end }} diff --git a/in-vcluster-metrics-svc.yaml b/in-vcluster-metrics-svc.yaml deleted file mode 100644 index 6e628cda6..000000000 --- a/in-vcluster-metrics-svc.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - labels: - k8s-app: metrics-server - name: metrics-server - namespace: kube-system -spec: - ports: - - name: https - port: 443 - protocol: TCP - targetPort: 8443 - selector: - k8s-app: metrics-server - sessionAffinity: None - type: ClusterIP \ No newline at end of file diff --git a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go index feb813416..1c7c947f7 100644 --- a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go +++ b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go @@ -41,6 +41,8 @@ type EndpointController struct { Log loghelper.Logger provider provider + + singleBinaryDistro bool } func NewEndpointController(ctx *options.ControllerContext, provider provider) *EndpointController { @@ -52,6 +54,7 @@ func NewEndpointController(ctx *options.ControllerContext, provider provider) *E VirtualManagerCache: ctx.VirtualManager.GetCache(), Log: loghelper.New("kubernetes-default-endpoint-controller"), provider: provider, + singleBinaryDistro: ctx.Options.SingleBinaryDistro, } } @@ -68,6 +71,14 @@ func (e *EndpointController) Reconcile(ctx context.Context, _ ctrl.Request) (ctr if err != nil { 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 { + return ctrl.Result{RequeueAfter: time.Second}, err + } + } return ctrl.Result{}, nil } @@ -100,6 +111,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" + + // 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{} diff --git a/pkg/controllers/resources/endpoints/syncer.go b/pkg/controllers/resources/endpoints/syncer.go index 606e3526f..280ae435e 100644 --- a/pkg/controllers/resources/endpoints/syncer.go +++ b/pkg/controllers/resources/endpoints/syncer.go @@ -40,17 +40,10 @@ 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.NamespacedName == specialservices.DefaultKubernetesSvcKey || - req.NamespacedName == specialservices.VclusterProxyMetricsSvcKey { - return true, nil - } else if _, ok := specialservices.Default.SpecialServicesToSync()[req.NamespacedName]; ok { + if req.NamespacedName == specialservices.DefaultKubernetesSvcKey { return true, nil } - // if req.Namespace == "default" && req.Name == "kubernetes" { - // return true, nil - // } - svc := &corev1.Service{} err := ctx.VirtualClient.Get(ctx.Context, types.NamespacedName{ Namespace: req.Namespace, diff --git a/pkg/controllers/resources/services/syncer.go b/pkg/controllers/resources/services/syncer.go index 2cbcb8357..68d7cd346 100644 --- a/pkg/controllers/resources/services/syncer.go +++ b/pkg/controllers/resources/services/syncer.go @@ -159,10 +159,8 @@ func (s *serviceSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.Re specialServices := specialservices.Default.SpecialServicesToSync() svc, ok := specialServices[req.NamespacedName] - if ok && req.NamespacedName == specialservices.DefaultKubernetesSvcKey { + if ok { return true, svc(ctx, ctx.CurrentNamespace, s.serviceName, req.NamespacedName, TranslateServicePorts) - } else if ok && req.NamespacedName == specialservices.VclusterProxyMetricsSvcKey { - return true, svc(ctx, ctx.CurrentNamespace, s.serviceName+"-metrics-proxy", req.NamespacedName, func(p []corev1.ServicePort) []corev1.ServicePort { return []corev1.ServicePort{} }) } return false, nil diff --git a/pkg/metricsapiservice/register.go b/pkg/metricsapiservice/register.go index 93b4a2d61..f5b308fdb 100644 --- a/pkg/metricsapiservice/register.go +++ b/pkg/metricsapiservice/register.go @@ -2,10 +2,15 @@ package metricsapiservice import ( "context" + "fmt" "math" + "os" + "path" "time" + "github.com/loft-sh/vcluster/pkg/constants" "github.com/loft-sh/vcluster/pkg/setup/options" + "github.com/loft-sh/vcluster/pkg/util/applier" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" @@ -19,9 +24,14 @@ import ( kerrors "k8s.io/apimachinery/pkg/api/errors" ) +var ( + ErrNoMetricsManifests = fmt.Errorf("no metrics server service manifests found") +) + const ( - MetricsVersion = "v1beta1" - MetricsAPIService = MetricsVersion + "." + metrics.GroupName // "v1beta1.metrics.k8s.io" + ManifestRelativePath = "metrics-server/service.yaml" + MetricsVersion = "v1beta1" + MetricsAPIService = MetricsVersion + "." + metrics.GroupName // "v1beta1.metrics.k8s.io" ) func checkExistingAPIService(ctx context.Context, client client.Client) bool { @@ -52,9 +62,9 @@ func applyOperation(ctx context.Context, operationFunc wait.ConditionWithContext }, operationFunc) } -func deleteOperation(_ context.Context, client client.Client) wait.ConditionWithContextFunc { +func deleteOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { - err := client.Delete(ctx, &apiregistrationv1.APIService{ + err := ctrlCtx.VirtualManager.GetClient().Delete(ctx, &apiregistrationv1.APIService{ ObjectMeta: v1.ObjectMeta{ Name: MetricsAPIService, }, @@ -72,8 +82,23 @@ func deleteOperation(_ context.Context, client client.Client) wait.ConditionWith } } -func createOperation(_ context.Context, client client.Client) wait.ConditionWithContextFunc { +func createOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { + if !ctrlCtx.Options.SingleBinaryDistro { + // create aux metrics server service in vcluster + manifestPath := path.Join(constants.ContainerManifestsFolder, ManifestRelativePath) + if _, err := os.Stat(manifestPath); os.IsNotExist(err) { + klog.Errorf("error, no metrics server manifest file found %v", ErrNoMetricsManifests) + return false, nil + } + + err := applier.ApplyManifestFile(ctrlCtx.Context, ctrlCtx.VirtualManager.GetConfig(), manifestPath) + if err != nil { + klog.Errorf("error applying metrics server manifest %v", err) + return false, nil + } + } + spec := apiregistrationv1.APIServiceSpec{ Service: &apiregistrationv1.ServiceReference{ Name: "metrics-server", @@ -85,7 +110,6 @@ func createOperation(_ context.Context, client client.Client) wait.ConditionWith Version: MetricsVersion, VersionPriority: 100, InsecureSkipTLSVerify: true, - // CABundle: []byte(`-----BEGIN CERTIFICATE-----\nMIIC/jCCAeagAwIBAgIBADANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDEwprdWJl\ncm5ldGVzMB4XDTIyMDgxNjAzMDgwMFoXDTMyMDgxMzAzMDgwMFowFTETMBEGA1UE\nAxMKa3ViZXJuZXRlczCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMf1\nzJTnoUVt+OH4GG2qLFN4JlLoupTa3xFr+yhnJxf0LqVMBF6JKN/0khKEClFlO1lp\nXtWZHbz2yrQKB/3PZ7mWZiu5zcW4BxMFww6Je/2Ut5Y9KWcQgocdu9lQkhkCyPY9\no5RKVCEnuSB/rfYPD2d97Q4bNDwH6+/DT6vOE1KcNY7nzLynWcSa+xAh/ArG+PZO\noUIZ1kjDbE7NL7IJV1yWTvmVokOV9BDTll4HPctvhMblYMzZbxG6uB1SniJlxzuB\nF1+uBrVV/v5H4c4xyko5WTFwhAMe1aLM4NEpE6xCEoJmB6Qgrhun1AMukUBuJkqE\nxWykUfLkLK1lgFU2OdsCAwEAAaNZMFcwDgYDVR0PAQH/BAQDAgKkMA8GA1UdEwEB\n/wQFMAMBAf8wHQYDVR0OBBYEFHwYuwZ+21NrYghdBkY0HG9CkgfmMBUGA1UdEQQO\nMAyCCmt1YmVybmV0ZXMwDQYJKoZIhvcNAQELBQADggEBALgbrX/UUXSLi/uRZ5h7\nKMluBCBFs1ATBfgzlMHqlCdYJTR/Eps3NWBy26+yC0URYIlnDHqtQs14eHPo0iJR\nrff6BTQvyS5jZqkZyvkQWjE8J9xXVJe6vew8yQbM4pgZZIXjRRBjV7Mlr6bzjY74\nxxlI1JnCP75+/3sJnQrZDy6lcg4MsacvojHYdXEgHX8MccEZ6Gt6x2++plsfmtax\nFspo3R7HuP1eM4jlZ24rRj+w2bwyTPZ22wpc6eAljrR2qjlYWHEmTMKQS+MjJk5q\nzg2frjE410c8bqLZpa61Npun/q7gpxIAXlj914DJEiv+9DotjQuFJ59mQFYrU9iA\nfVE=\n-----END CERTIFICATE-----`), } apiService := &apiregistrationv1.APIService{ @@ -94,7 +118,7 @@ func createOperation(_ context.Context, client client.Client) wait.ConditionWith }, } - _, err := controllerutil.CreateOrUpdate(ctx, client, apiService, func() error { + _, err := controllerutil.CreateOrUpdate(ctx, ctrlCtx.VirtualManager.GetClient(), apiService, func() error { apiService.Spec = spec return nil }) @@ -111,13 +135,13 @@ func createOperation(_ context.Context, client client.Client) wait.ConditionWith } } -func RegisterOrDeregisterAPIService(ctx context.Context, options *options.VirtualClusterOptions, client client.Client) error { +func RegisterOrDeregisterAPIService(ctx *options.ControllerContext) error { // check if the api service should get created - exists := checkExistingAPIService(ctx, client) - if options.ProxyMetricsServer { - return applyOperation(ctx, createOperation(ctx, client)) - } else if !options.ProxyMetricsServer && exists { - return applyOperation(ctx, deleteOperation(ctx, client)) + exists := checkExistingAPIService(ctx.Context, ctx.VirtualManager.GetClient()) + if ctx.Options.ProxyMetricsServer { + return applyOperation(ctx.Context, createOperation(ctx)) + } else if !ctx.Options.ProxyMetricsServer && exists { + return applyOperation(ctx.Context, deleteOperation(ctx)) } return nil diff --git a/pkg/setup/controllers.go b/pkg/setup/controllers.go index 1dec866ab..fa56b90c9 100644 --- a/pkg/setup/controllers.go +++ b/pkg/setup/controllers.go @@ -191,8 +191,7 @@ func StartManagers(controllerContext *options.ControllerContext, syncers []synce } func RegisterOrDeregisterAPIService(ctx *options.ControllerContext) { - // check api-service for metrics server - err := metricsapiservice.RegisterOrDeregisterAPIService(ctx.Context, ctx.Options, ctx.VirtualManager.GetClient()) + err := metricsapiservice.RegisterOrDeregisterAPIService(ctx) if err != nil { klog.Errorf("Error registering metrics apiservice: %v", err) } diff --git a/pkg/setup/options/flags.go b/pkg/setup/options/flags.go index eb43817f3..ae60ddffa 100644 --- a/pkg/setup/options/flags.go +++ b/pkg/setup/options/flags.go @@ -61,6 +61,7 @@ func AddFlags(flags *pflag.FlagSet, options *VirtualClusterOptions) { flags.StringVar(&options.HostMetricsBindAddress, "host-metrics-bind-address", "0", "If set, metrics for the controller manager for the resources managed in the host cluster will be exposed at this address") flags.StringVar(&options.VirtualMetricsBindAddress, "virtual-metrics-bind-address", "0", "If set, metrics for the controller manager for the resources managed in the virtual cluster will be exposed at this address") + flags.BoolVar(&options.SingleBinaryDistro, "single-binary-distro", true, "Indicates vcluster wether the distro used is single binary (k3s/k0s) or k8s/eks") flags.BoolVar(&options.MountPhysicalHostPaths, "mount-physical-host-paths", false, "If enabled, syncer will rewite hostpaths in synced pod volumes") flags.BoolVar(&options.MultiNamespaceMode, "multi-namespace-mode", false, "If enabled, syncer will create a namespace for each virtual namespace and use the original names for the synced namespaced resources") flags.StringSliceVar(&options.NamespaceLabels, "namespace-labels", []string{}, "Defines one or more labels that will be added to the namespaces synced in the multi-namespace mode. Format: \"labelKey=labelValue\". Multiple values can be passed in a comma-separated string.") diff --git a/pkg/setup/options/options.go b/pkg/setup/options/options.go index dbe0fb3c0..9a9641286 100644 --- a/pkg/setup/options/options.go +++ b/pkg/setup/options/options.go @@ -66,6 +66,8 @@ type VirtualClusterOptions struct { SyncLabels []string `json:"syncLabels,omitempty"` + SingleBinaryDistro bool `json:"singleBinaryDistro,omitempty"` + // hostpath mapper options // this is only needed if using vcluster-hostpath-mapper component // see: https://github.com/loft-sh/vcluster-hostpath-mapper diff --git a/pkg/specialservices/proxy_service_syncer.go b/pkg/specialservices/proxy_service_syncer.go index 39cde29f3..834189c34 100644 --- a/pkg/specialservices/proxy_service_syncer.go +++ b/pkg/specialservices/proxy_service_syncer.go @@ -2,10 +2,12 @@ package specialservices import ( synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context" + "github.com/loft-sh/vcluster/pkg/util/translate" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/equality" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" + "k8s.io/klog/v2" ) var ( @@ -15,6 +17,12 @@ var ( } ) +const ( + PhysicalSvcSelectorKeyApp = "app" + PhysicalSvcSelectorKeyRelease = "release" + PhysicalMetricsServerServiceNameSuffix = "-metrics-proxy" +) + func SyncVclusterProxyService(ctx *synccontext.SyncContext, svcNamespace, svcName string, @@ -25,8 +33,8 @@ func SyncVclusterProxyService(ctx *synccontext.SyncContext, // get physical service pObj := &corev1.Service{} err := pClient.Get(ctx.Context, types.NamespacedName{ - Namespace: svcNamespace, - Name: svcName, + Namespace: translate.Default.PhysicalNamespace(vSvcToSync.Namespace), // svcNamespace, + Name: svcName + PhysicalMetricsServerServiceNameSuffix, // svcName, }, pObj) if err != nil { @@ -37,6 +45,22 @@ func SyncVclusterProxyService(ctx *synccontext.SyncContext, return err } + // check if pobject has the expected selectors, if not update + // and make it point to the syncer pod + expectedPhysicalSvcSelectors := map[string]string{ + PhysicalSvcSelectorKeyApp: "vcluster", + PhysicalSvcSelectorKeyRelease: svcName, + } + + if !equality.Semantic.DeepEqual(pObj.Spec.Selector, expectedPhysicalSvcSelectors) { + pObj.Spec.Selector = expectedPhysicalSvcSelectors + err = pClient.Update(ctx.Context, pObj) + if err != nil { + klog.Errorf("error updating physical metrics server service object %v", err) + return err + } + } + vClient := ctx.VirtualClient vObj := &corev1.Service{} err = vClient.Get(ctx.Context, vSvcToSync, vObj) diff --git a/pkg/specialservices/resolver.go b/pkg/specialservices/resolver.go index e60685053..fe32c3211 100644 --- a/pkg/specialservices/resolver.go +++ b/pkg/specialservices/resolver.go @@ -1,6 +1,8 @@ package specialservices import ( + "os" + synccontext "github.com/loft-sh/vcluster/pkg/controllers/syncer/context" "github.com/loft-sh/vcluster/pkg/util/translate" "k8s.io/apimachinery/pkg/types" @@ -12,6 +14,8 @@ var Default = DefaultNameserverFinder() const ( DefaultKubeDNSServiceName = "kube-dns" DefaultKubeDNSServiceNamespace = "kube-system" + + DistroEnvKey = "SINGLE_BINARY_DISTRO" ) type SpecialServiceSyncer func( @@ -40,10 +44,15 @@ func (f *NameserverFinder) SpecialServicesToSync() map[types.NamespacedName]Spec } func DefaultNameserverFinder() Interface { + specialServicesMap := map[types.NamespacedName]SpecialServiceSyncer{ + DefaultKubernetesSvcKey: SyncKubernetesService, + } + + if isSingleBinaryDistro := os.Getenv(DistroEnvKey); isSingleBinaryDistro == "false" { + specialServicesMap[VclusterProxyMetricsSvcKey] = SyncVclusterProxyService + } + return &NameserverFinder{ - SpecialServices: map[types.NamespacedName]SpecialServiceSyncer{ - DefaultKubernetesSvcKey: SyncKubernetesService, - VclusterProxyMetricsSvcKey: SyncVclusterProxyService, - }, + SpecialServices: specialServicesMap, } } From b26d41cbe65a8887a32214d8d35f4050d92240ba Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 31 Oct 2023 17:38:53 +0530 Subject: [PATCH 04/17] fix values test Signed-off-by: Ishan Khare --- charts/k3s/values.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/charts/k3s/values.yaml b/charts/k3s/values.yaml index 69a7aa5d1..b16b8ce5b 100644 --- a/charts/k3s/values.yaml +++ b/charts/k3s/values.yaml @@ -267,9 +267,6 @@ podAnnotations: {} # The k3s token to use. If empty will generate one automatically k3sToken: "" -# The k3s token to use. If empty will generate one automatically -k3sToken: "" - # Service configurations service: type: ClusterIP From c41609375eb493177f286974586a04a4ef5c02d6 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 31 Oct 2023 17:39:54 +0530 Subject: [PATCH 05/17] fix lint errors Signed-off-by: Ishan Khare --- pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go | 1 - pkg/specialservices/proxy_service_syncer.go | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go index 1c7c947f7..2103f76f3 100644 --- a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go +++ b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go @@ -91,7 +91,6 @@ func (e *EndpointController) SetupWithManager(mgr ctrl.Manager) error { pfuncs := predicate.NewPredicateFuncs(pp) vp := func(object client.Object) bool { - if object.GetNamespace() == specialservices.DefaultKubernetesSvcKey.Namespace && object.GetName() == specialservices.DefaultKubernetesSvcKey.Name { return true } diff --git a/pkg/specialservices/proxy_service_syncer.go b/pkg/specialservices/proxy_service_syncer.go index 834189c34..c5d59c29b 100644 --- a/pkg/specialservices/proxy_service_syncer.go +++ b/pkg/specialservices/proxy_service_syncer.go @@ -24,17 +24,16 @@ const ( ) func SyncVclusterProxyService(ctx *synccontext.SyncContext, - svcNamespace, + _, svcName string, vSvcToSync types.NamespacedName, - svcPortTranslator ServicePortTranslator) error { - + _ ServicePortTranslator) error { pClient := ctx.PhysicalClient // get physical service pObj := &corev1.Service{} err := pClient.Get(ctx.Context, types.NamespacedName{ - Namespace: translate.Default.PhysicalNamespace(vSvcToSync.Namespace), // svcNamespace, - Name: svcName + PhysicalMetricsServerServiceNameSuffix, // svcName, + Namespace: translate.Default.PhysicalNamespace(vSvcToSync.Namespace), + Name: svcName + PhysicalMetricsServerServiceNameSuffix, }, pObj) if err != nil { From 6202d0635470003849cda0fcc6206f605edc7d67 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 31 Oct 2023 17:41:24 +0530 Subject: [PATCH 06/17] only add SANs when not in single binary distro Signed-off-by: Ishan Khare --- pkg/server/cert/cert.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pkg/server/cert/cert.go b/pkg/server/cert/cert.go index 69c04cb32..e065fe495 100644 --- a/pkg/server/cert/cert.go +++ b/pkg/server/cert/cert.go @@ -7,6 +7,7 @@ import ( "net" "os" + "github.com/loft-sh/vcluster/pkg/specialservices" "github.com/loft-sh/vcluster/pkg/util/certhelper" "k8s.io/apimachinery/pkg/util/sets" ) @@ -15,19 +16,27 @@ func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byt regen := false commonName := "kube-apiserver" extKeyUsage := []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth} - altNames := &certhelper.AltNames{ - DNSNames: []string{ - "kubernetes.default.svc." + clusterDomain, - "kubernetes.default.svc", - "kubernetes.default", - "kubernetes", - "localhost", + + dnsNames := []string{ + "kubernetes.default.svc." + clusterDomain, + "kubernetes.default.svc", + "kubernetes.default", + "kubernetes", + "localhost", + } + + if isSingleBinaryDistro := os.Getenv(specialservices.DistroEnvKey); isSingleBinaryDistro == "false" { + dnsNames = append(dnsNames, []string{ "metrics-server.kube-system.svc." + clusterDomain, "metrics-server.kube-system.svc", "metrics-server.kube-system", "metrics-server", - }, - IPs: []net.IP{net.ParseIP("127.0.0.1")}, + }...) + } + + altNames := &certhelper.AltNames{ + DNSNames: dnsNames, + IPs: []net.IP{net.ParseIP("127.0.0.1")}, } addSANs(altNames, SANs) From a823b6931854ed5c1fd3f25cbd778bff35f7b873 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 31 Oct 2023 17:52:25 +0530 Subject: [PATCH 07/17] remove unwanted configmap Signed-off-by: Ishan Khare --- .../k8s/templates/proxy-metrics-server.yaml | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 charts/k8s/templates/proxy-metrics-server.yaml diff --git a/charts/k8s/templates/proxy-metrics-server.yaml b/charts/k8s/templates/proxy-metrics-server.yaml deleted file mode 100644 index b1ca8c099..000000000 --- a/charts/k8s/templates/proxy-metrics-server.yaml +++ /dev/null @@ -1,25 +0,0 @@ -{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled}} -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ .Release.Name }}-metrics-server - namespace: {{ .Release.Namespace }} -data: - metrics-server.yaml: |- - apiVersion: v1 - kind: Service - metadata: - labels: - k8s-app: metrics-server - name: metrics-server - namespace: kube-system - spec: - - name: https - port: 443 - protocol: TCP - targetPort: https - selector: - k8s-app: metrics-server - sessionAffinity: None - type: ClusterIP -{{- end }} \ No newline at end of file From a26f223e1ca48a38527a1b383eabfaa4c05d3a90 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 31 Oct 2023 17:54:32 +0530 Subject: [PATCH 08/17] modify eks chart for api registration fix Signed-off-by: Ishan Khare --- charts/eks/templates/metrics-proxy.yaml | 59 +++++++++++++++++++++ charts/eks/templates/syncer-deployment.yaml | 16 +++++- 2 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 charts/eks/templates/metrics-proxy.yaml diff --git a/charts/eks/templates/metrics-proxy.yaml b/charts/eks/templates/metrics-proxy.yaml new file mode 100644 index 000000000..41ae37c2e --- /dev/null +++ b/charts/eks/templates/metrics-proxy.yaml @@ -0,0 +1,59 @@ +{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-metrics-proxy + namespace: {{ .Release.Namespace }} + labels: + app: vcluster-metrics-proxy + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" + {{- $annotations := merge .Values.globalAnnotations .Values.syncer.serviceAnnotations }} + {{- if $annotations }} + annotations: +{{ toYaml $annotations | indent 4 }} + {{- end }} +spec: + ports: + - name: https + port: 443 + targetPort: 8443 + protocol: TCP + - name: kubelet + port: 10250 + targetPort: 8443 + protocol: TCP + selector: + app: vcluster + release: {{ .Release.Name }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-metrics-proxy + namespace: {{ .Release.Namespace }} + {{- if .Values.globalAnnotations }} + annotations: +{{ toYaml .Values.globalAnnotations | indent 4 }} + {{- end }} +data: + service.yaml: |- + apiVersion: v1 + kind: Service + metadata: + labels: + k8s-app: metrics-server + name: metrics-server + namespace: kube-system + spec: + ports: + - name: https + port: 443 + protocol: TCP + targetPort: 8443 + selector: + k8s-app: metrics-server + sessionAffinity: None + type: ClusterIP +{{- end }} \ No newline at end of file diff --git a/charts/eks/templates/syncer-deployment.yaml b/charts/eks/templates/syncer-deployment.yaml index c8cd8403b..d034b1375 100644 --- a/charts/eks/templates/syncer-deployment.yaml +++ b/charts/eks/templates/syncer-deployment.yaml @@ -92,6 +92,11 @@ spec: configMap: name: coredns-custom optional: true + {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} + - name: metrics-proxy-svc + configMap: + name: {{ .Release.Name }}-metrics-proxy + {{- end }} {{- if .Values.syncer.priorityClassName }} priorityClassName: {{ .Values.syncer.priorityClassName }} {{- end }} @@ -118,7 +123,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 @@ -169,6 +174,7 @@ spec: {{- end }} {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled}} - --proxy-metrics-server=true + - --single-binary-distro=false {{- end }} {{- if .Values.coredns.integrated }} - --integrated-coredns=true @@ -228,6 +234,10 @@ 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 @@ -235,6 +245,10 @@ spec: mountPath: /tmp - mountPath: /pki name: certs + {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} + - name: metrics-proxy-svc + mountPath: /manifests/metrics-server + {{- end }} {{- if .Values.syncer.volumeMounts }} {{ toYaml .Values.syncer.volumeMounts | indent 10 }} {{- end }} From 0b9273df4e86e1a7ea487f872f3934c6957e7147 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Thu, 2 Nov 2023 20:17:21 +0530 Subject: [PATCH 09/17] move service creation from chart to code address other minor review comments Signed-off-by: Ishan Khare --- charts/eks/templates/metrics-proxy.yaml | 59 -------- charts/eks/templates/syncer-deployment.yaml | 9 -- charts/k8s/templates/metrics-proxy.yaml | 59 -------- charts/k8s/templates/syncer-deployment.yaml | 9 -- .../k8sdefaultendpoint/k8sdefaultendpoint.go | 7 + pkg/metricsapiservice/register.go | 143 +++++++++++++----- pkg/specialservices/proxy_service_syncer.go | 4 +- 7 files changed, 118 insertions(+), 172 deletions(-) delete mode 100644 charts/eks/templates/metrics-proxy.yaml delete mode 100644 charts/k8s/templates/metrics-proxy.yaml diff --git a/charts/eks/templates/metrics-proxy.yaml b/charts/eks/templates/metrics-proxy.yaml deleted file mode 100644 index 41ae37c2e..000000000 --- a/charts/eks/templates/metrics-proxy.yaml +++ /dev/null @@ -1,59 +0,0 @@ -{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} -apiVersion: v1 -kind: Service -metadata: - name: {{ .Release.Name }}-metrics-proxy - namespace: {{ .Release.Namespace }} - labels: - app: vcluster-metrics-proxy - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" - {{- $annotations := merge .Values.globalAnnotations .Values.syncer.serviceAnnotations }} - {{- if $annotations }} - annotations: -{{ toYaml $annotations | indent 4 }} - {{- end }} -spec: - ports: - - name: https - port: 443 - targetPort: 8443 - protocol: TCP - - name: kubelet - port: 10250 - targetPort: 8443 - protocol: TCP - selector: - app: vcluster - release: {{ .Release.Name }} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ .Release.Name }}-metrics-proxy - namespace: {{ .Release.Namespace }} - {{- if .Values.globalAnnotations }} - annotations: -{{ toYaml .Values.globalAnnotations | indent 4 }} - {{- end }} -data: - service.yaml: |- - apiVersion: v1 - kind: Service - metadata: - labels: - k8s-app: metrics-server - name: metrics-server - namespace: kube-system - spec: - ports: - - name: https - port: 443 - protocol: TCP - targetPort: 8443 - selector: - k8s-app: metrics-server - sessionAffinity: None - type: ClusterIP -{{- end }} \ No newline at end of file diff --git a/charts/eks/templates/syncer-deployment.yaml b/charts/eks/templates/syncer-deployment.yaml index d034b1375..bbf6847e7 100644 --- a/charts/eks/templates/syncer-deployment.yaml +++ b/charts/eks/templates/syncer-deployment.yaml @@ -92,11 +92,6 @@ spec: configMap: name: coredns-custom optional: true - {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} - - name: metrics-proxy-svc - configMap: - name: {{ .Release.Name }}-metrics-proxy - {{- end }} {{- if .Values.syncer.priorityClassName }} priorityClassName: {{ .Values.syncer.priorityClassName }} {{- end }} @@ -245,10 +240,6 @@ spec: mountPath: /tmp - mountPath: /pki name: certs - {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} - - name: metrics-proxy-svc - mountPath: /manifests/metrics-server - {{- end }} {{- if .Values.syncer.volumeMounts }} {{ toYaml .Values.syncer.volumeMounts | indent 10 }} {{- end }} diff --git a/charts/k8s/templates/metrics-proxy.yaml b/charts/k8s/templates/metrics-proxy.yaml deleted file mode 100644 index 41ae37c2e..000000000 --- a/charts/k8s/templates/metrics-proxy.yaml +++ /dev/null @@ -1,59 +0,0 @@ -{{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} -apiVersion: v1 -kind: Service -metadata: - name: {{ .Release.Name }}-metrics-proxy - namespace: {{ .Release.Namespace }} - labels: - app: vcluster-metrics-proxy - chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" - {{- $annotations := merge .Values.globalAnnotations .Values.syncer.serviceAnnotations }} - {{- if $annotations }} - annotations: -{{ toYaml $annotations | indent 4 }} - {{- end }} -spec: - ports: - - name: https - port: 443 - targetPort: 8443 - protocol: TCP - - name: kubelet - port: 10250 - targetPort: 8443 - protocol: TCP - selector: - app: vcluster - release: {{ .Release.Name }} ---- -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ .Release.Name }}-metrics-proxy - namespace: {{ .Release.Namespace }} - {{- if .Values.globalAnnotations }} - annotations: -{{ toYaml .Values.globalAnnotations | indent 4 }} - {{- end }} -data: - service.yaml: |- - apiVersion: v1 - kind: Service - metadata: - labels: - k8s-app: metrics-server - name: metrics-server - namespace: kube-system - spec: - ports: - - name: https - port: 443 - protocol: TCP - targetPort: 8443 - selector: - k8s-app: metrics-server - sessionAffinity: None - type: ClusterIP -{{- end }} \ No newline at end of file diff --git a/charts/k8s/templates/syncer-deployment.yaml b/charts/k8s/templates/syncer-deployment.yaml index 888aa761b..33d31dcf2 100644 --- a/charts/k8s/templates/syncer-deployment.yaml +++ b/charts/k8s/templates/syncer-deployment.yaml @@ -122,11 +122,6 @@ spec: configMap: name: coredns-custom optional: true - {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} - - name: metrics-proxy-svc - configMap: - name: {{ .Release.Name }}-metrics-proxy - {{- end }} {{- if .Values.syncer.priorityClassName }} priorityClassName: {{ .Values.syncer.priorityClassName }} {{- end }} @@ -283,10 +278,6 @@ spec: mountPath: /manifests/coredns readOnly: true {{- end }} - {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} - - name: metrics-proxy-svc - mountPath: /manifests/metrics-server - {{- end }} {{- if .Values.syncer.volumeMounts }} {{ toYaml .Values.syncer.volumeMounts | indent 10 }} {{- end }} diff --git a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go index 2103f76f3..1257e44c8 100644 --- a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go +++ b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go @@ -95,6 +95,13 @@ func (e *EndpointController) SetupWithManager(mgr ctrl.Manager) error { return true } + if !e.singleBinaryDistro { + if object.GetNamespace() == specialservices.VclusterProxyMetricsSvcKey.Namespace && + object.GetName() == specialservices.VclusterProxyMetricsSvcKey.Name { + return true + } + } + return false } vfuncs := predicate.NewPredicateFuncs(vp) diff --git a/pkg/metricsapiservice/register.go b/pkg/metricsapiservice/register.go index f5b308fdb..67773d970 100644 --- a/pkg/metricsapiservice/register.go +++ b/pkg/metricsapiservice/register.go @@ -4,15 +4,13 @@ import ( "context" "fmt" "math" - "os" - "path" "time" - "github.com/loft-sh/vcluster/pkg/constants" "github.com/loft-sh/vcluster/pkg/setup/options" - "github.com/loft-sh/vcluster/pkg/util/applier" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" @@ -29,15 +27,15 @@ var ( ) const ( - ManifestRelativePath = "metrics-server/service.yaml" - MetricsVersion = "v1beta1" - MetricsAPIService = MetricsVersion + "." + metrics.GroupName // "v1beta1.metrics.k8s.io" + ManifestRelativePath = "metrics-server/service.yaml" + MetricsVersion = "v1beta1" + MetricsAPIServiceName = MetricsVersion + "." + metrics.GroupName // "v1beta1.metrics.k8s.io" ) func checkExistingAPIService(ctx context.Context, client client.Client) bool { var exists bool _ = applyOperation(ctx, func(ctx context.Context) (bool, error) { - err := client.Get(ctx, types.NamespacedName{Name: MetricsAPIService}, &apiregistrationv1.APIService{}) + err := client.Get(ctx, types.NamespacedName{Name: MetricsAPIServiceName}, &apiregistrationv1.APIService{}) if err != nil { if kerrors.IsNotFound(err) { return true, nil @@ -65,8 +63,8 @@ func applyOperation(ctx context.Context, operationFunc wait.ConditionWithContext func deleteOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { err := ctrlCtx.VirtualManager.GetClient().Delete(ctx, &apiregistrationv1.APIService{ - ObjectMeta: v1.ObjectMeta{ - Name: MetricsAPIService, + ObjectMeta: metav1.ObjectMeta{ + Name: MetricsAPIServiceName, }, }) if err != nil { @@ -74,7 +72,7 @@ func deleteOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithConte return true, nil } - klog.Errorf("error creating api service %v", err) + klog.Errorf("error deleting api service %v", err) return false, nil } @@ -84,37 +82,114 @@ func deleteOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithConte func createOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { + spec := apiregistrationv1.APIServiceSpec{ + Group: metrics.GroupName, + GroupPriorityMinimum: 100, + Version: MetricsVersion, + VersionPriority: 100, + } + if !ctrlCtx.Options.SingleBinaryDistro { - // create aux metrics server service in vcluster - manifestPath := path.Join(constants.ContainerManifestsFolder, ManifestRelativePath) - if _, err := os.Stat(manifestPath); os.IsNotExist(err) { - klog.Errorf("error, no metrics server manifest file found %v", ErrNoMetricsManifests) - return false, nil + // in this case we register an apiservice with a service reference object + // this service is created as a special service and the physical-virtual + // pair makes sure the service discovery happens as expected in even non single + // binary distros like k8s and eks + spec.Service = &apiregistrationv1.ServiceReference{ + Name: "metrics-server", + Namespace: "kube-system", + Port: pointer.Int32(443), } - err := applier.ApplyManifestFile(ctrlCtx.Context, ctrlCtx.VirtualManager.GetConfig(), manifestPath) + spec.InsecureSkipTLSVerify = true + + // manifestPath := path.Join(constants.ContainerManifestsFolder, ManifestRelativePath) + // if _, err := os.Stat(manifestPath); os.IsNotExist(err) { + // klog.Errorf("error, no metrics server manifest file found %v", ErrNoMetricsManifests) + // return false, nil + // } + + // err := applier.ApplyManifestFile(ctrlCtx.Context, ctrlCtx.VirtualManager.GetConfig(), manifestPath) + // if err != nil { + // klog.Errorf("error applying metrics server manifest %v", err) + // return false, nil + // } + + // create aux metrics server service in vcluster + auxVirtualSvc := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: "metrics-server", + Namespace: "kube-system", + Labels: map[string]string{ + "k8s-app": "metrics-server", + }, + }, + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + { + Name: "https", + Port: 443, + Protocol: "TCP", + TargetPort: intstr.FromInt(8443), + }, + }, + Selector: map[string]string{ + "k8s-app": "metrics-server", + }, + SessionAffinity: corev1.ServiceAffinityNone, + Type: corev1.ServiceTypeClusterIP, + }, + } + err := ctrlCtx.VirtualManager.GetClient().Create(ctx, auxVirtualSvc) if err != nil { - klog.Errorf("error applying metrics server manifest %v", err) - return false, nil + if !kerrors.IsAlreadyExists(err) { + klog.Errorf("error creating metrics server service inside vcluster %v", err) + return false, nil + } } - } - spec := apiregistrationv1.APIServiceSpec{ - Service: &apiregistrationv1.ServiceReference{ - Name: "metrics-server", - Namespace: "kube-system", - Port: pointer.Int32(443), - }, - Group: metrics.GroupName, - GroupPriorityMinimum: 100, - Version: MetricsVersion, - VersionPriority: 100, - InsecureSkipTLSVerify: true, + // create aux metrics service in host cluster + hostMetricsProxySvc := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: ctrlCtx.Options.ServiceName + "-metrics-proxy", + Namespace: ctrlCtx.CurrentNamespace, + Labels: map[string]string{ + "app": "vcluster-metrics-proxy", + "release": ctrlCtx.Options.Name, + }, + }, + Spec: corev1.ServiceSpec{ + Ports: []corev1.ServicePort{ + { + Name: "https", + Port: 443, + Protocol: "TCP", + TargetPort: intstr.FromInt(8443), + }, + { + Name: "kubelet", + Port: 10250, + Protocol: "TCP", + TargetPort: intstr.FromInt(8443), + }, + }, + Selector: map[string]string{ + "app": "vcluster", + "release": ctrlCtx.Options.Name, + }, + }, + } + err = ctrlCtx.LocalManager.GetClient().Create(ctx, hostMetricsProxySvc) + if err != nil { + if !kerrors.IsAlreadyExists(err) { + klog.Errorf("error create host metrics proxy service %v", err) + return false, nil + } + } } apiService := &apiregistrationv1.APIService{ - ObjectMeta: v1.ObjectMeta{ - Name: MetricsAPIService, + ObjectMeta: metav1.ObjectMeta{ + Name: MetricsAPIServiceName, }, } diff --git a/pkg/specialservices/proxy_service_syncer.go b/pkg/specialservices/proxy_service_syncer.go index c5d59c29b..b0e490707 100644 --- a/pkg/specialservices/proxy_service_syncer.go +++ b/pkg/specialservices/proxy_service_syncer.go @@ -27,7 +27,8 @@ func SyncVclusterProxyService(ctx *synccontext.SyncContext, _, svcName string, vSvcToSync types.NamespacedName, - _ ServicePortTranslator) error { + _ ServicePortTranslator, +) error { pClient := ctx.PhysicalClient // get physical service pObj := &corev1.Service{} @@ -35,7 +36,6 @@ func SyncVclusterProxyService(ctx *synccontext.SyncContext, Namespace: translate.Default.PhysicalNamespace(vSvcToSync.Namespace), Name: svcName + PhysicalMetricsServerServiceNameSuffix, }, pObj) - if err != nil { if kerrors.IsNotFound(err) { return nil From 3fac312364849988ee4be1771c9495ce3790b639 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Thu, 2 Nov 2023 20:28:50 +0530 Subject: [PATCH 10/17] add deletion of aux services in case of toggle Signed-off-by: Ishan Khare --- pkg/metricsapiservice/register.go | 52 +++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/pkg/metricsapiservice/register.go b/pkg/metricsapiservice/register.go index 67773d970..c02b1c3f8 100644 --- a/pkg/metricsapiservice/register.go +++ b/pkg/metricsapiservice/register.go @@ -30,6 +30,9 @@ const ( ManifestRelativePath = "metrics-server/service.yaml" MetricsVersion = "v1beta1" MetricsAPIServiceName = MetricsVersion + "." + metrics.GroupName // "v1beta1.metrics.k8s.io" + + AuxVirtualSvcName = "metrics-server" + AuxVirtualSvcNamespace = "kube-system" ) func checkExistingAPIService(ctx context.Context, client client.Client) bool { @@ -62,6 +65,34 @@ func applyOperation(ctx context.Context, operationFunc wait.ConditionWithContext func deleteOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { + if !ctrlCtx.Options.SingleBinaryDistro { + auxVirtualSvc := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: AuxVirtualSvcName, + Namespace: AuxVirtualSvcNamespace, + }, + } + err := ctrlCtx.VirtualManager.GetClient().Delete(ctx, auxVirtualSvc) + if err != nil { + if !kerrors.IsNotFound(err) { + return false, nil + } + } + + hostMetricsProxySvc := &corev1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: ctrlCtx.Options.ServiceName + "-metrics-proxy", + Namespace: ctrlCtx.CurrentNamespace, + }, + } + err = ctrlCtx.LocalManager.GetClient().Delete(ctx, hostMetricsProxySvc) + if err != nil { + if !kerrors.IsNotFound(err) { + return false, nil + } + } + } + err := ctrlCtx.VirtualManager.GetClient().Delete(ctx, &apiregistrationv1.APIService{ ObjectMeta: metav1.ObjectMeta{ Name: MetricsAPIServiceName, @@ -95,30 +126,17 @@ func createOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithConte // pair makes sure the service discovery happens as expected in even non single // binary distros like k8s and eks spec.Service = &apiregistrationv1.ServiceReference{ - Name: "metrics-server", - Namespace: "kube-system", + Name: AuxVirtualSvcName, + Namespace: AuxVirtualSvcNamespace, Port: pointer.Int32(443), } - spec.InsecureSkipTLSVerify = true - // manifestPath := path.Join(constants.ContainerManifestsFolder, ManifestRelativePath) - // if _, err := os.Stat(manifestPath); os.IsNotExist(err) { - // klog.Errorf("error, no metrics server manifest file found %v", ErrNoMetricsManifests) - // return false, nil - // } - - // err := applier.ApplyManifestFile(ctrlCtx.Context, ctrlCtx.VirtualManager.GetConfig(), manifestPath) - // if err != nil { - // klog.Errorf("error applying metrics server manifest %v", err) - // return false, nil - // } - // create aux metrics server service in vcluster auxVirtualSvc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ - Name: "metrics-server", - Namespace: "kube-system", + Name: AuxVirtualSvcName, + Namespace: AuxVirtualSvcNamespace, Labels: map[string]string{ "k8s-app": "metrics-server", }, From 7b39ff4043ba706c828cca85655f4db6fa49f7c5 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Fri, 3 Nov 2023 21:47:04 +0530 Subject: [PATCH 11/17] add e2e for metrics server api registration check Signed-off-by: Ishan Khare --- .github/workflows/e2e.yaml | 13 +++++ .../e2e_metrics_proxy_test.go | 56 +++++++++++++++++++ test/e2e_metrics_proxy/metricsProxy.go | 36 ++++++++++++ test/e2e_metrics_proxy/values.yaml | 6 ++ 4 files changed, 111 insertions(+) create mode 100644 test/e2e_metrics_proxy/e2e_metrics_proxy_test.go create mode 100644 test/e2e_metrics_proxy/metricsProxy.go create mode 100644 test/e2e_metrics_proxy/values.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index b24115453..ee2f25950 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -205,6 +205,19 @@ jobs: -f ${{ matrix.test-suite-path }}/values.yaml \ "${extraArgs[@]}" continue-on-error: true + + - name: Install metrics server in host cluster + uses: 'deliverybot/helm@v1' + id: install-metrics-server + with: + release: metrics-server + namespace: kube-system + chart: metrics-server + repo: https://kubernetes-sigs.github.io/metrics-server/ + version: 3.11.0 + values: |- + defaultArgs: + - --kubelet-insecure-tls - name: Wait until vcluster is ready id: wait-until-vcluster-is-ready diff --git a/test/e2e_metrics_proxy/e2e_metrics_proxy_test.go b/test/e2e_metrics_proxy/e2e_metrics_proxy_test.go new file mode 100644 index 000000000..8d707dbea --- /dev/null +++ b/test/e2e_metrics_proxy/e2e_metrics_proxy_test.go @@ -0,0 +1,56 @@ +package e2emetricsproxy + +import ( + "context" + "testing" + + "github.com/loft-sh/log" + "github.com/loft-sh/vcluster/test/framework" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" + "k8s.io/apimachinery/pkg/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" + + // Enable cloud provider auth + _ "k8s.io/client-go/plugin/pkg/client/auth" + // Register tests +) + +var ( + scheme = runtime.NewScheme() +) + +func init() { + _ = clientgoscheme.AddToScheme(scheme) + // API extensions are not in the above scheme set, + // and must thus be added separately. + _ = apiextensionsv1beta1.AddToScheme(scheme) + _ = apiextensionsv1.AddToScheme(scheme) + _ = apiregistrationv1.AddToScheme(scheme) +} + +// TestRunE2ETargetNamespaceTests checks configuration parameters (specified through flags) and then runs +// E2E tests using the Ginkgo runner. +// If a "report directory" is specified, one or more JUnit test reports will be +// generated in this directory, and cluster logs will also be saved. +// This function is called on each Ginkgo node in parallel mode. +func TestRunE2ETargetNamespaceTests(t *testing.T) { + gomega.RegisterFailHandler(ginkgo.Fail) + err := framework.CreateFramework(context.Background(), scheme) + if err != nil { + log.GetInstance().Fatalf("Error setting up framework: %v", err) + } + + var _ = ginkgo.AfterSuite(func() { + err = framework.DefaultFramework.Cleanup() + if err != nil { + log.GetInstance().Warnf("Error executing testsuite cleanup: %v", err) + } + }) + + ginkgo.RunSpecs(t, "Vcluster e2eProxyMetricsServer suite") +} diff --git a/test/e2e_metrics_proxy/metricsProxy.go b/test/e2e_metrics_proxy/metricsProxy.go new file mode 100644 index 000000000..b54f0ae04 --- /dev/null +++ b/test/e2e_metrics_proxy/metricsProxy.go @@ -0,0 +1,36 @@ +package e2emetricsproxy + +import ( + "context" + "time" + + "github.com/loft-sh/vcluster/pkg/metricsapiservice" + "github.com/loft-sh/vcluster/test/framework" + "github.com/onsi/ginkgo/v2" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" + apiregistrationv1clientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1" +) + +var _ = ginkgo.Describe("Target Namespace", func() { + f := framework.DefaultFramework + + ginkgo.It("Make sure the metrics api service is registered and available", func() { + err := wait.PollUntilContextTimeout(f.Context, time.Second, time.Minute*1, false, func(ctx context.Context) (done bool, err error) { + apiRegistrationClient := apiregistrationv1clientset.NewForConfigOrDie(f.VclusterConfig) + apiService, err := apiRegistrationClient.APIServices().Get(f.Context, metricsapiservice.MetricsAPIServiceName, metav1.GetOptions{}) + if err != nil { + return false, nil + } + + if apiService.Status.Conditions[0].Type != apiregistrationv1.Available { + return false, nil + } + + return true, nil + }) + framework.ExpectNoError(err) + }) +}) diff --git a/test/e2e_metrics_proxy/values.yaml b/test/e2e_metrics_proxy/values.yaml new file mode 100644 index 000000000..c3d366048 --- /dev/null +++ b/test/e2e_metrics_proxy/values.yaml @@ -0,0 +1,6 @@ +proxy: + metricsServer: + nodes: + enabled: true + pods: + enabled: true \ No newline at end of file From c98aba12ee29bc661a75af190cabca0b8bd5d213 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Fri, 3 Nov 2023 22:10:57 +0530 Subject: [PATCH 12/17] fix metrics server helm chart install Signed-off-by: Ishan Khare --- .github/workflows/e2e.yaml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index ee2f25950..fbcdbbc59 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -207,17 +207,11 @@ jobs: continue-on-error: true - name: Install metrics server in host cluster - uses: 'deliverybot/helm@v1' id: install-metrics-server - with: - release: metrics-server - namespace: kube-system - chart: metrics-server - repo: https://kubernetes-sigs.github.io/metrics-server/ - version: 3.11.0 - values: |- - defaultArgs: - - --kubelet-insecure-tls + 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 defaultArgs={--kubelet-insecure-tls} -n kube-system - name: Wait until vcluster is ready id: wait-until-vcluster-is-ready From eecb93540ee009017d8b856493919ba3e3686986 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Thu, 9 Nov 2023 11:31:33 +0530 Subject: [PATCH 13/17] modify special service default setup and remove env var Signed-off-by: Ishan Khare --- charts/eks/templates/syncer-deployment.yaml | 4 - charts/k8s/templates/syncer-deployment.yaml | 4 - .../k8sdefaultendpoint/k8sdefaultendpoint.go | 1 - pkg/server/cert/cert.go | 5 +- pkg/server/cert/syncer.go | 6 +- pkg/setup/initialize.go | 3 + pkg/specialservices/resolver.go | 13 +- .../metrics/pkg/apis/metrics/v1alpha1/doc.go | 24 + .../pkg/apis/metrics/v1alpha1/generated.pb.go | 1758 +++++++++++++++++ .../pkg/apis/metrics/v1alpha1/generated.proto | 95 + .../pkg/apis/metrics/v1alpha1/register.go | 53 + .../pkg/apis/metrics/v1alpha1/types.go | 101 + .../v1alpha1/zz_generated.conversion.go | 209 ++ .../metrics/v1alpha1/zz_generated.deepcopy.go | 186 ++ .../client/clientset/versioned/scheme/doc.go | 20 + .../clientset/versioned/scheme/register.go | 58 + .../versioned/typed/metrics/v1beta1/doc.go | 20 + .../metrics/v1beta1/generated_expansion.go | 23 + .../typed/metrics/v1beta1/metrics_client.go | 112 ++ .../typed/metrics/v1beta1/nodemetrics.go | 98 + .../typed/metrics/v1beta1/podmetrics.go | 103 + vendor/modules.txt | 3 + 22 files changed, 2881 insertions(+), 18 deletions(-) create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/doc.go create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.pb.go create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.proto create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/register.go create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.conversion.go create mode 100644 vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.deepcopy.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/doc.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/register.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/doc.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/generated_expansion.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/metrics_client.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/nodemetrics.go create mode 100644 vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/podmetrics.go diff --git a/charts/eks/templates/syncer-deployment.yaml b/charts/eks/templates/syncer-deployment.yaml index bbf6847e7..e1b4b93b1 100644 --- a/charts/eks/templates/syncer-deployment.yaml +++ b/charts/eks/templates/syncer-deployment.yaml @@ -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 diff --git a/charts/k8s/templates/syncer-deployment.yaml b/charts/k8s/templates/syncer-deployment.yaml index 33d31dcf2..d6fec6fd9 100644 --- a/charts/k8s/templates/syncer-deployment.yaml +++ b/charts/k8s/templates/syncer-deployment.yaml @@ -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 diff --git a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go index 1257e44c8..c3d6009c8 100644 --- a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go +++ b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go @@ -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 { diff --git a/pkg/server/cert/cert.go b/pkg/server/cert/cert.go index e065fe495..a4db7efec 100644 --- a/pkg/server/cert/cert.go +++ b/pkg/server/cert/cert.go @@ -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} @@ -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", diff --git a/pkg/server/cert/syncer.go b/pkg/server/cert/syncer.go index 71a056395..868d9a7fe 100644 --- a/pkg/server/cert/syncer.go +++ b/pkg/server/cert/syncer.go @@ -44,6 +44,8 @@ func NewSyncer(_ context.Context, currentNamespace string, currentNamespaceClien serviceName: options.ServiceName, currentNamespace: currentNamespace, currentNamespaceCient: currentNamespaceClient, + + isSingleBinaryDistro: options.SingleBinaryDistro, }, nil } @@ -67,6 +69,8 @@ type syncer struct { currentCert []byte currentKey []byte currentSANs []string + + isSingleBinaryDistro bool } func (s *syncer) Name() string { @@ -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 } diff --git a/pkg/setup/initialize.go b/pkg/setup/initialize.go index 63c69284a..0187d0203 100644 --- a/pkg/setup/initialize.go +++ b/pkg/setup/initialize.go @@ -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" @@ -57,6 +58,8 @@ func Initialize( return err } + specialservices.SetDefault(options) + return nil } diff --git a/pkg/specialservices/resolver.go b/pkg/specialservices/resolver.go index fe32c3211..dd784d04f 100644 --- a/pkg/specialservices/resolver.go +++ b/pkg/specialservices/resolver.go @@ -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" @@ -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 } diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/doc.go b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/doc.go new file mode 100644 index 000000000..8e06b2205 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/doc.go @@ -0,0 +1,24 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// +k8s:deepcopy-gen=package +// +k8s:protobuf-gen=package +// +k8s:conversion-gen=k8s.io/metrics/pkg/apis/metrics +// +k8s:openapi-gen=true +// +groupName=metrics.k8s.io + +// Package v1alpha1 is the v1alpha1 version of the metrics API. +package v1alpha1 // import "k8s.io/metrics/pkg/apis/metrics/v1alpha1" diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.pb.go b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.pb.go new file mode 100644 index 000000000..c472bacd4 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.pb.go @@ -0,0 +1,1758 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: k8s.io/kubernetes/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.proto + +package v1alpha1 + +import ( + fmt "fmt" + + io "io" + + proto "github.com/gogo/protobuf/proto" + github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" + + k8s_io_api_core_v1 "k8s.io/api/core/v1" + k8s_io_apimachinery_pkg_api_resource "k8s.io/apimachinery/pkg/api/resource" + resource "k8s.io/apimachinery/pkg/api/resource" + + math "math" + math_bits "math/bits" + reflect "reflect" + strings "strings" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +func (m *ContainerMetrics) Reset() { *m = ContainerMetrics{} } +func (*ContainerMetrics) ProtoMessage() {} +func (*ContainerMetrics) Descriptor() ([]byte, []int) { + return fileDescriptor_4bcbecebae081ea6, []int{0} +} +func (m *ContainerMetrics) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *ContainerMetrics) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *ContainerMetrics) XXX_Merge(src proto.Message) { + xxx_messageInfo_ContainerMetrics.Merge(m, src) +} +func (m *ContainerMetrics) XXX_Size() int { + return m.Size() +} +func (m *ContainerMetrics) XXX_DiscardUnknown() { + xxx_messageInfo_ContainerMetrics.DiscardUnknown(m) +} + +var xxx_messageInfo_ContainerMetrics proto.InternalMessageInfo + +func (m *NodeMetrics) Reset() { *m = NodeMetrics{} } +func (*NodeMetrics) ProtoMessage() {} +func (*NodeMetrics) Descriptor() ([]byte, []int) { + return fileDescriptor_4bcbecebae081ea6, []int{1} +} +func (m *NodeMetrics) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NodeMetrics) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *NodeMetrics) XXX_Merge(src proto.Message) { + xxx_messageInfo_NodeMetrics.Merge(m, src) +} +func (m *NodeMetrics) XXX_Size() int { + return m.Size() +} +func (m *NodeMetrics) XXX_DiscardUnknown() { + xxx_messageInfo_NodeMetrics.DiscardUnknown(m) +} + +var xxx_messageInfo_NodeMetrics proto.InternalMessageInfo + +func (m *NodeMetricsList) Reset() { *m = NodeMetricsList{} } +func (*NodeMetricsList) ProtoMessage() {} +func (*NodeMetricsList) Descriptor() ([]byte, []int) { + return fileDescriptor_4bcbecebae081ea6, []int{2} +} +func (m *NodeMetricsList) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *NodeMetricsList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *NodeMetricsList) XXX_Merge(src proto.Message) { + xxx_messageInfo_NodeMetricsList.Merge(m, src) +} +func (m *NodeMetricsList) XXX_Size() int { + return m.Size() +} +func (m *NodeMetricsList) XXX_DiscardUnknown() { + xxx_messageInfo_NodeMetricsList.DiscardUnknown(m) +} + +var xxx_messageInfo_NodeMetricsList proto.InternalMessageInfo + +func (m *PodMetrics) Reset() { *m = PodMetrics{} } +func (*PodMetrics) ProtoMessage() {} +func (*PodMetrics) Descriptor() ([]byte, []int) { + return fileDescriptor_4bcbecebae081ea6, []int{3} +} +func (m *PodMetrics) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PodMetrics) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *PodMetrics) XXX_Merge(src proto.Message) { + xxx_messageInfo_PodMetrics.Merge(m, src) +} +func (m *PodMetrics) XXX_Size() int { + return m.Size() +} +func (m *PodMetrics) XXX_DiscardUnknown() { + xxx_messageInfo_PodMetrics.DiscardUnknown(m) +} + +var xxx_messageInfo_PodMetrics proto.InternalMessageInfo + +func (m *PodMetricsList) Reset() { *m = PodMetricsList{} } +func (*PodMetricsList) ProtoMessage() {} +func (*PodMetricsList) Descriptor() ([]byte, []int) { + return fileDescriptor_4bcbecebae081ea6, []int{4} +} +func (m *PodMetricsList) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *PodMetricsList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil +} +func (m *PodMetricsList) XXX_Merge(src proto.Message) { + xxx_messageInfo_PodMetricsList.Merge(m, src) +} +func (m *PodMetricsList) XXX_Size() int { + return m.Size() +} +func (m *PodMetricsList) XXX_DiscardUnknown() { + xxx_messageInfo_PodMetricsList.DiscardUnknown(m) +} + +var xxx_messageInfo_PodMetricsList proto.InternalMessageInfo + +func init() { + proto.RegisterType((*ContainerMetrics)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.ContainerMetrics") + proto.RegisterMapType((k8s_io_api_core_v1.ResourceList)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.ContainerMetrics.UsageEntry") + proto.RegisterType((*NodeMetrics)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.NodeMetrics") + proto.RegisterMapType((k8s_io_api_core_v1.ResourceList)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.NodeMetrics.UsageEntry") + proto.RegisterType((*NodeMetricsList)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.NodeMetricsList") + proto.RegisterType((*PodMetrics)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.PodMetrics") + proto.RegisterType((*PodMetricsList)(nil), "k8s.io.metrics.pkg.apis.metrics.v1alpha1.PodMetricsList") +} + +func init() { + proto.RegisterFile("k8s.io/kubernetes/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.proto", fileDescriptor_4bcbecebae081ea6) +} + +var fileDescriptor_4bcbecebae081ea6 = []byte{ + // 661 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x56, 0x41, 0x4f, 0x13, 0x41, + 0x18, 0xed, 0xd0, 0x96, 0xc0, 0x54, 0x11, 0xf7, 0x44, 0x7a, 0xd8, 0x92, 0x9e, 0x1a, 0x13, 0x66, + 0x85, 0xa0, 0x21, 0x9c, 0xcc, 0x0a, 0x07, 0x13, 0x41, 0xd9, 0xa0, 0x46, 0xf4, 0xe0, 0x74, 0x3b, + 0x6e, 0xc7, 0xb2, 0x3b, 0x9b, 0x99, 0xd9, 0x92, 0xde, 0x8c, 0x7a, 0xf2, 0x64, 0xe2, 0x9f, 0xc2, + 0x78, 0xe1, 0xc8, 0x45, 0x90, 0xf5, 0xee, 0x0f, 0xf0, 0x64, 0x76, 0x76, 0xb6, 0x5b, 0x29, 0xc2, + 0xca, 0xc1, 0x13, 0xb7, 0xee, 0x37, 0xf3, 0xde, 0xfb, 0xe6, 0x7d, 0x6f, 0x26, 0x85, 0x5b, 0xbd, + 0x15, 0x81, 0x28, 0xb3, 0x7a, 0x51, 0x9b, 0xf0, 0x80, 0x48, 0x22, 0xac, 0x3e, 0x09, 0x3a, 0x8c, + 0x5b, 0x7a, 0xc1, 0x27, 0x92, 0x53, 0x57, 0x58, 0x61, 0xcf, 0xb3, 0x70, 0x48, 0xc5, 0xb0, 0xd0, + 0x5f, 0xc4, 0xbb, 0x61, 0x17, 0x2f, 0x5a, 0x1e, 0x09, 0x08, 0xc7, 0x92, 0x74, 0x50, 0xc8, 0x99, + 0x64, 0x46, 0x2b, 0x45, 0x22, 0xbd, 0x11, 0x85, 0x3d, 0x0f, 0x25, 0xc8, 0x61, 0x21, 0x43, 0xd6, + 0x17, 0x3c, 0x2a, 0xbb, 0x51, 0x1b, 0xb9, 0xcc, 0xb7, 0x3c, 0xe6, 0x31, 0x4b, 0x11, 0xb4, 0xa3, + 0xd7, 0xea, 0x4b, 0x7d, 0xa8, 0x5f, 0x29, 0x71, 0xbd, 0xa9, 0x5b, 0xc2, 0x21, 0xb5, 0x5c, 0xc6, + 0x89, 0xd5, 0x1f, 0x13, 0xaf, 0x2f, 0xe7, 0x7b, 0x7c, 0xec, 0x76, 0x69, 0x40, 0xf8, 0x20, 0xeb, + 0xdd, 0xe2, 0x44, 0xb0, 0x88, 0xbb, 0xe4, 0x9f, 0x50, 0xea, 0xc4, 0xf8, 0x2c, 0x2d, 0xeb, 0x6f, + 0x28, 0x1e, 0x05, 0x92, 0xfa, 0xe3, 0x32, 0x77, 0x2f, 0x02, 0x08, 0xb7, 0x4b, 0x7c, 0x7c, 0x1a, + 0xd7, 0x7c, 0x5f, 0x86, 0xb3, 0xf7, 0x59, 0x20, 0x71, 0x82, 0xd8, 0x48, 0x5d, 0x34, 0xe6, 0x61, + 0x25, 0xc0, 0x3e, 0x99, 0x03, 0xf3, 0xa0, 0x35, 0x6d, 0x5f, 0xdb, 0x3f, 0x6a, 0x94, 0xe2, 0xa3, + 0x46, 0x65, 0x13, 0xfb, 0xc4, 0x51, 0x2b, 0x46, 0x0c, 0x60, 0x35, 0x12, 0xd8, 0x23, 0x73, 0x13, + 0xf3, 0xe5, 0x56, 0x6d, 0x69, 0x1d, 0x15, 0x9d, 0x0c, 0x3a, 0xad, 0x86, 0x9e, 0x24, 0x3c, 0xeb, + 0x81, 0xe4, 0x03, 0xfb, 0x03, 0xd0, 0x5a, 0x55, 0x55, 0xfc, 0x75, 0xd4, 0x68, 0x8c, 0x0f, 0x06, + 0x39, 0xda, 0xeb, 0x87, 0x54, 0xc8, 0x77, 0xc7, 0xe7, 0x6e, 0x49, 0x5a, 0xfe, 0x78, 0xdc, 0x58, + 0x28, 0x32, 0x3a, 0xb4, 0x15, 0xe1, 0x40, 0x52, 0x39, 0x70, 0xd2, 0xa3, 0xd5, 0xbb, 0x10, 0xe6, + 0xbd, 0x19, 0xb3, 0xb0, 0xdc, 0x23, 0x83, 0xd4, 0x13, 0x27, 0xf9, 0x69, 0xac, 0xc1, 0x6a, 0x1f, + 0xef, 0x46, 0x89, 0x07, 0xa0, 0x55, 0x5b, 0x42, 0x99, 0x07, 0xa3, 0x2a, 0x99, 0x11, 0xe8, 0x0c, + 0x15, 0x05, 0x5e, 0x9d, 0x58, 0x01, 0xcd, 0x9f, 0x15, 0x58, 0xdb, 0x64, 0x1d, 0x92, 0x0d, 0xe0, + 0x15, 0x9c, 0x4a, 0x92, 0xd1, 0xc1, 0x12, 0x2b, 0xc1, 0xda, 0xd2, 0xed, 0xf3, 0xc8, 0x95, 0xcb, + 0x18, 0xf5, 0x17, 0xd1, 0xa3, 0xf6, 0x1b, 0xe2, 0xca, 0x0d, 0x22, 0xb1, 0x6d, 0x68, 0x2b, 0x61, + 0x5e, 0x73, 0x86, 0xac, 0xc6, 0x0b, 0x38, 0x9d, 0xc4, 0x42, 0x48, 0xec, 0x87, 0xba, 0xff, 0x5b, + 0xc5, 0x24, 0xb6, 0xa9, 0x4f, 0xec, 0x9b, 0x9a, 0x7c, 0x7a, 0x3b, 0x23, 0x71, 0x72, 0x3e, 0xe3, + 0x29, 0x9c, 0xdc, 0xa3, 0x41, 0x87, 0xed, 0xcd, 0x95, 0x2f, 0x76, 0x26, 0x67, 0x5e, 0x8b, 0x38, + 0x96, 0x94, 0x05, 0xf6, 0x8c, 0x66, 0x9f, 0x7c, 0xa6, 0x58, 0x1c, 0xcd, 0x66, 0x7c, 0x1b, 0xa6, + 0xae, 0xa2, 0x52, 0x77, 0xaf, 0x78, 0xea, 0x46, 0xdc, 0xbd, 0x0a, 0x1c, 0x68, 0x7e, 0x05, 0xf0, + 0xc6, 0x88, 0x25, 0xc9, 0xc1, 0x8c, 0x97, 0x63, 0xa1, 0x2b, 0x38, 0xb7, 0x04, 0xad, 0x22, 0x37, + 0xab, 0xcd, 0x9c, 0xca, 0x2a, 0x23, 0x81, 0xdb, 0x81, 0x55, 0x2a, 0x89, 0x2f, 0xf4, 0x83, 0x71, + 0xe7, 0x52, 0xa3, 0xb3, 0xaf, 0x67, 0xe3, 0x7a, 0x90, 0x70, 0x39, 0x29, 0x65, 0xf3, 0x73, 0x19, + 0xc2, 0xc7, 0xac, 0x73, 0x75, 0x7b, 0xce, 0xbd, 0x3d, 0x01, 0x84, 0x6e, 0xf6, 0xf6, 0x0a, 0x7d, + 0x83, 0x56, 0x2f, 0xff, 0x6e, 0xe7, 0x16, 0x0d, 0x57, 0x84, 0x33, 0xa2, 0xd0, 0xfc, 0x02, 0xe0, + 0x4c, 0x3e, 0x95, 0xff, 0x10, 0xb1, 0xe7, 0x7f, 0x46, 0x6c, 0xb9, 0xf8, 0xd9, 0xf2, 0x36, 0xcf, + 0x4e, 0x98, 0xbd, 0xb9, 0x7f, 0x62, 0x96, 0x0e, 0x4e, 0xcc, 0xd2, 0xe1, 0x89, 0x59, 0x7a, 0x1b, + 0x9b, 0x60, 0x3f, 0x36, 0xc1, 0x41, 0x6c, 0x82, 0xc3, 0xd8, 0x04, 0xdf, 0x63, 0x13, 0x7c, 0xfa, + 0x61, 0x96, 0x76, 0x5a, 0x45, 0xff, 0xd8, 0xfc, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x8c, 0xe2, 0xb1, + 0xf3, 0x1c, 0x09, 0x00, 0x00, +} + +func (m *ContainerMetrics) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *ContainerMetrics) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *ContainerMetrics) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Usage) > 0 { + keysForUsage := make([]string, 0, len(m.Usage)) + for k := range m.Usage { + keysForUsage = append(keysForUsage, string(k)) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForUsage) + for iNdEx := len(keysForUsage) - 1; iNdEx >= 0; iNdEx-- { + v := m.Usage[k8s_io_api_core_v1.ResourceName(keysForUsage[iNdEx])] + baseI := i + { + size, err := ((*resource.Quantity)(&v)).MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + i -= len(keysForUsage[iNdEx]) + copy(dAtA[i:], keysForUsage[iNdEx]) + i = encodeVarintGenerated(dAtA, i, uint64(len(keysForUsage[iNdEx]))) + i-- + dAtA[i] = 0xa + i = encodeVarintGenerated(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x12 + } + } + i -= len(m.Name) + copy(dAtA[i:], m.Name) + i = encodeVarintGenerated(dAtA, i, uint64(len(m.Name))) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *NodeMetrics) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *NodeMetrics) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NodeMetrics) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Usage) > 0 { + keysForUsage := make([]string, 0, len(m.Usage)) + for k := range m.Usage { + keysForUsage = append(keysForUsage, string(k)) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForUsage) + for iNdEx := len(keysForUsage) - 1; iNdEx >= 0; iNdEx-- { + v := m.Usage[k8s_io_api_core_v1.ResourceName(keysForUsage[iNdEx])] + baseI := i + { + size, err := ((*resource.Quantity)(&v)).MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + i -= len(keysForUsage[iNdEx]) + copy(dAtA[i:], keysForUsage[iNdEx]) + i = encodeVarintGenerated(dAtA, i, uint64(len(keysForUsage[iNdEx]))) + i-- + dAtA[i] = 0xa + i = encodeVarintGenerated(dAtA, i, uint64(baseI-i)) + i-- + dAtA[i] = 0x22 + } + } + { + size, err := m.Window.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.Timestamp.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ObjectMeta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *NodeMetricsList) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *NodeMetricsList) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *NodeMetricsList) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Items) > 0 { + for iNdEx := len(m.Items) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Items[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.ListMeta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *PodMetrics) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PodMetrics) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PodMetrics) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Containers) > 0 { + for iNdEx := len(m.Containers) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Containers[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + { + size, err := m.Window.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + { + size, err := m.Timestamp.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.ObjectMeta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *PodMetricsList) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *PodMetricsList) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *PodMetricsList) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Items) > 0 { + for iNdEx := len(m.Items) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Items[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.ListMeta.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenerated(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintGenerated(dAtA []byte, offset int, v uint64) int { + offset -= sovGenerated(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *ContainerMetrics) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Name) + n += 1 + l + sovGenerated(uint64(l)) + if len(m.Usage) > 0 { + for k, v := range m.Usage { + _ = k + _ = v + l = ((*resource.Quantity)(&v)).Size() + mapEntrySize := 1 + len(k) + sovGenerated(uint64(len(k))) + 1 + l + sovGenerated(uint64(l)) + n += mapEntrySize + 1 + sovGenerated(uint64(mapEntrySize)) + } + } + return n +} + +func (m *NodeMetrics) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ObjectMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Timestamp.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Window.Size() + n += 1 + l + sovGenerated(uint64(l)) + if len(m.Usage) > 0 { + for k, v := range m.Usage { + _ = k + _ = v + l = ((*resource.Quantity)(&v)).Size() + mapEntrySize := 1 + len(k) + sovGenerated(uint64(len(k))) + 1 + l + sovGenerated(uint64(l)) + n += mapEntrySize + 1 + sovGenerated(uint64(mapEntrySize)) + } + } + return n +} + +func (m *NodeMetricsList) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ListMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) + if len(m.Items) > 0 { + for _, e := range m.Items { + l = e.Size() + n += 1 + l + sovGenerated(uint64(l)) + } + } + return n +} + +func (m *PodMetrics) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ObjectMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Timestamp.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.Window.Size() + n += 1 + l + sovGenerated(uint64(l)) + if len(m.Containers) > 0 { + for _, e := range m.Containers { + l = e.Size() + n += 1 + l + sovGenerated(uint64(l)) + } + } + return n +} + +func (m *PodMetricsList) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ListMeta.Size() + n += 1 + l + sovGenerated(uint64(l)) + if len(m.Items) > 0 { + for _, e := range m.Items { + l = e.Size() + n += 1 + l + sovGenerated(uint64(l)) + } + } + return n +} + +func sovGenerated(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenerated(x uint64) (n int) { + return sovGenerated(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ContainerMetrics) String() string { + if this == nil { + return "nil" + } + keysForUsage := make([]string, 0, len(this.Usage)) + for k := range this.Usage { + keysForUsage = append(keysForUsage, string(k)) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForUsage) + mapStringForUsage := "k8s_io_api_core_v1.ResourceList{" + for _, k := range keysForUsage { + mapStringForUsage += fmt.Sprintf("%v: %v,", k, this.Usage[k8s_io_api_core_v1.ResourceName(k)]) + } + mapStringForUsage += "}" + s := strings.Join([]string{`&ContainerMetrics{`, + `Name:` + fmt.Sprintf("%v", this.Name) + `,`, + `Usage:` + mapStringForUsage + `,`, + `}`, + }, "") + return s +} +func (this *NodeMetrics) String() string { + if this == nil { + return "nil" + } + keysForUsage := make([]string, 0, len(this.Usage)) + for k := range this.Usage { + keysForUsage = append(keysForUsage, string(k)) + } + github_com_gogo_protobuf_sortkeys.Strings(keysForUsage) + mapStringForUsage := "k8s_io_api_core_v1.ResourceList{" + for _, k := range keysForUsage { + mapStringForUsage += fmt.Sprintf("%v: %v,", k, this.Usage[k8s_io_api_core_v1.ResourceName(k)]) + } + mapStringForUsage += "}" + s := strings.Join([]string{`&NodeMetrics{`, + `ObjectMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ObjectMeta), "ObjectMeta", "v1.ObjectMeta", 1), `&`, ``, 1) + `,`, + `Timestamp:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Timestamp), "Time", "v1.Time", 1), `&`, ``, 1) + `,`, + `Window:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Window), "Duration", "v1.Duration", 1), `&`, ``, 1) + `,`, + `Usage:` + mapStringForUsage + `,`, + `}`, + }, "") + return s +} +func (this *NodeMetricsList) String() string { + if this == nil { + return "nil" + } + repeatedStringForItems := "[]NodeMetrics{" + for _, f := range this.Items { + repeatedStringForItems += strings.Replace(strings.Replace(f.String(), "NodeMetrics", "NodeMetrics", 1), `&`, ``, 1) + "," + } + repeatedStringForItems += "}" + s := strings.Join([]string{`&NodeMetricsList{`, + `ListMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ListMeta), "ListMeta", "v1.ListMeta", 1), `&`, ``, 1) + `,`, + `Items:` + repeatedStringForItems + `,`, + `}`, + }, "") + return s +} +func (this *PodMetrics) String() string { + if this == nil { + return "nil" + } + repeatedStringForContainers := "[]ContainerMetrics{" + for _, f := range this.Containers { + repeatedStringForContainers += strings.Replace(strings.Replace(f.String(), "ContainerMetrics", "ContainerMetrics", 1), `&`, ``, 1) + "," + } + repeatedStringForContainers += "}" + s := strings.Join([]string{`&PodMetrics{`, + `ObjectMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ObjectMeta), "ObjectMeta", "v1.ObjectMeta", 1), `&`, ``, 1) + `,`, + `Timestamp:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Timestamp), "Time", "v1.Time", 1), `&`, ``, 1) + `,`, + `Window:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.Window), "Duration", "v1.Duration", 1), `&`, ``, 1) + `,`, + `Containers:` + repeatedStringForContainers + `,`, + `}`, + }, "") + return s +} +func (this *PodMetricsList) String() string { + if this == nil { + return "nil" + } + repeatedStringForItems := "[]PodMetrics{" + for _, f := range this.Items { + repeatedStringForItems += strings.Replace(strings.Replace(f.String(), "PodMetrics", "PodMetrics", 1), `&`, ``, 1) + "," + } + repeatedStringForItems += "}" + s := strings.Join([]string{`&PodMetricsList{`, + `ListMeta:` + strings.Replace(strings.Replace(fmt.Sprintf("%v", this.ListMeta), "ListMeta", "v1.ListMeta", 1), `&`, ``, 1) + `,`, + `Items:` + repeatedStringForItems + `,`, + `}`, + }, "") + return s +} +func valueToStringGenerated(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *ContainerMetrics) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: ContainerMetrics: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ContainerMetrics: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Name", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Name = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Usage", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Usage == nil { + m.Usage = make(k8s_io_api_core_v1.ResourceList) + } + var mapkey k8s_io_api_core_v1.ResourceName + mapvalue := &resource.Quantity{} + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthGenerated + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthGenerated + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = k8s_io_api_core_v1.ResourceName(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthGenerated + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthGenerated + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &resource.Quantity{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Usage[k8s_io_api_core_v1.ResourceName(mapkey)] = ((k8s_io_apimachinery_pkg_api_resource.Quantity)(*mapvalue)) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *NodeMetrics) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: NodeMetrics: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NodeMetrics: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ObjectMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ObjectMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Timestamp.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Window", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Window.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Usage", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Usage == nil { + m.Usage = make(k8s_io_api_core_v1.ResourceList) + } + var mapkey k8s_io_api_core_v1.ResourceName + mapvalue := &resource.Quantity{} + for iNdEx < postIndex { + entryPreIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + if fieldNum == 1 { + var stringLenmapkey uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLenmapkey |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLenmapkey := int(stringLenmapkey) + if intStringLenmapkey < 0 { + return ErrInvalidLengthGenerated + } + postStringIndexmapkey := iNdEx + intStringLenmapkey + if postStringIndexmapkey < 0 { + return ErrInvalidLengthGenerated + } + if postStringIndexmapkey > l { + return io.ErrUnexpectedEOF + } + mapkey = k8s_io_api_core_v1.ResourceName(dAtA[iNdEx:postStringIndexmapkey]) + iNdEx = postStringIndexmapkey + } else if fieldNum == 2 { + var mapmsglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + mapmsglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if mapmsglen < 0 { + return ErrInvalidLengthGenerated + } + postmsgIndex := iNdEx + mapmsglen + if postmsgIndex < 0 { + return ErrInvalidLengthGenerated + } + if postmsgIndex > l { + return io.ErrUnexpectedEOF + } + mapvalue = &resource.Quantity{} + if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { + return err + } + iNdEx = postmsgIndex + } else { + iNdEx = entryPreIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > postIndex { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + m.Usage[k8s_io_api_core_v1.ResourceName(mapkey)] = ((k8s_io_apimachinery_pkg_api_resource.Quantity)(*mapvalue)) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *NodeMetricsList) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: NodeMetricsList: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NodeMetricsList: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ListMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ListMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Items", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Items = append(m.Items, NodeMetrics{}) + if err := m.Items[len(m.Items)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PodMetrics) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PodMetrics: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PodMetrics: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ObjectMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ObjectMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Timestamp.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Window", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Window.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Containers", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Containers = append(m.Containers, ContainerMetrics{}) + if err := m.Containers[len(m.Containers)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PodMetricsList) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PodMetricsList: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PodMetricsList: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ListMeta", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ListMeta.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Items", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenerated + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Items = append(m.Items, PodMetrics{}) + if err := m.Items[len(m.Items)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenerated(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenerated + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenerated + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenerated + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenerated + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenerated + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenerated + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenerated = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenerated = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenerated = fmt.Errorf("proto: unexpected end of group") +) diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.proto b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.proto new file mode 100644 index 000000000..d1938a85c --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/generated.proto @@ -0,0 +1,95 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + + +// This file was autogenerated by go-to-protobuf. Do not edit it manually! + +syntax = "proto2"; + +package k8s.io.metrics.pkg.apis.metrics.v1alpha1; + +import "k8s.io/api/core/v1/generated.proto"; +import "k8s.io/apimachinery/pkg/api/resource/generated.proto"; +import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; +import "k8s.io/apimachinery/pkg/runtime/generated.proto"; +import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; + +// Package-wide variables from generator "generated". +option go_package = "k8s.io/metrics/pkg/apis/metrics/v1alpha1"; + +// ContainerMetrics sets resource usage metrics of a container. +message ContainerMetrics { + // Container name corresponding to the one from pod.spec.containers. + optional string name = 1; + + // The memory usage is the memory working set. + map usage = 2; +} + +// NodeMetrics sets resource usage metrics of a node. +message NodeMetrics { + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + // +optional + optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + optional k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2; + + optional k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3; + + // The memory usage is the memory working set. + map usage = 4; +} + +// NodeMetricsList is a list of NodeMetrics. +message NodeMetricsList { + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + + // List of node metrics. + repeated NodeMetrics items = 2; +} + +// PodMetrics sets resource usage metrics of a pod. +message PodMetrics { + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + // +optional + optional k8s.io.apimachinery.pkg.apis.meta.v1.ObjectMeta metadata = 1; + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + optional k8s.io.apimachinery.pkg.apis.meta.v1.Time timestamp = 2; + + optional k8s.io.apimachinery.pkg.apis.meta.v1.Duration window = 3; + + // Metrics for all containers are collected within the same time window. + repeated ContainerMetrics containers = 4; +} + +// PodMetricsList is a list of PodMetrics. +message PodMetricsList { + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + optional k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 1; + + // List of pod metrics. + repeated PodMetrics items = 2; +} + diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/register.go b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/register.go new file mode 100644 index 000000000..3e5359a8e --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/register.go @@ -0,0 +1,53 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name use in this package +const GroupName = "metrics.k8s.io" + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder points to a list of functions added to Scheme. + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + localSchemeBuilder = &SchemeBuilder + // AddToScheme applies all the stored functions to the scheme. + AddToScheme = SchemeBuilder.AddToScheme +) + +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &NodeMetrics{}, + &NodeMetricsList{}, + &PodMetrics{}, + &PodMetricsList{}, + ) + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go new file mode 100644 index 000000000..871a3b177 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/types.go @@ -0,0 +1,101 @@ +/* +Copyright 2017 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +import ( + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +resourceName=nodes +// +genclient:readonly +// +genclient:nonNamespaced +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NodeMetrics sets resource usage metrics of a node. +type NodeMetrics struct { + metav1.TypeMeta `json:",inline"` + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` + Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` + + // The memory usage is the memory working set. + Usage v1.ResourceList `json:"usage" protobuf:"bytes,4,rep,name=usage,casttype=k8s.io/api/core/v1.ResourceList,castkey=k8s.io/api/core/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NodeMetricsList is a list of NodeMetrics. +type NodeMetricsList struct { + metav1.TypeMeta `json:",inline"` + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // List of node metrics. + Items []NodeMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` +} + +// +genclient +// +resourceName=pods +// +genclient:readonly +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// PodMetrics sets resource usage metrics of a pod. +type PodMetrics struct { + metav1.TypeMeta `json:",inline"` + // Standard object's metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata + // +optional + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // The following fields define time interval from which metrics were + // collected from the interval [Timestamp-Window, Timestamp]. + Timestamp metav1.Time `json:"timestamp" protobuf:"bytes,2,opt,name=timestamp"` + Window metav1.Duration `json:"window" protobuf:"bytes,3,opt,name=window"` + + // Metrics for all containers are collected within the same time window. + Containers []ContainerMetrics `json:"containers" protobuf:"bytes,4,rep,name=containers"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// PodMetricsList is a list of PodMetrics. +type PodMetricsList struct { + metav1.TypeMeta `json:",inline"` + // Standard list metadata. + // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + // List of pod metrics. + Items []PodMetrics `json:"items" protobuf:"bytes,2,rep,name=items"` +} + +// ContainerMetrics sets resource usage metrics of a container. +type ContainerMetrics struct { + // Container name corresponding to the one from pod.spec.containers. + Name string `json:"name" protobuf:"bytes,1,opt,name=name"` + // The memory usage is the memory working set. + Usage v1.ResourceList `json:"usage" protobuf:"bytes,2,rep,name=usage,casttype=k8s.io/api/core/v1.ResourceList,castkey=k8s.io/api/core/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"` +} diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.conversion.go b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.conversion.go new file mode 100644 index 000000000..f29d64659 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.conversion.go @@ -0,0 +1,209 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by conversion-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + unsafe "unsafe" + + v1 "k8s.io/api/core/v1" + conversion "k8s.io/apimachinery/pkg/conversion" + runtime "k8s.io/apimachinery/pkg/runtime" + metrics "k8s.io/metrics/pkg/apis/metrics" +) + +func init() { + localSchemeBuilder.Register(RegisterConversions) +} + +// RegisterConversions adds conversion functions to the given scheme. +// Public to allow building arbitrary schemes. +func RegisterConversions(s *runtime.Scheme) error { + if err := s.AddGeneratedConversionFunc((*ContainerMetrics)(nil), (*metrics.ContainerMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(a.(*ContainerMetrics), b.(*metrics.ContainerMetrics), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*metrics.ContainerMetrics)(nil), (*ContainerMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(a.(*metrics.ContainerMetrics), b.(*ContainerMetrics), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*NodeMetrics)(nil), (*metrics.NodeMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(a.(*NodeMetrics), b.(*metrics.NodeMetrics), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*metrics.NodeMetrics)(nil), (*NodeMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(a.(*metrics.NodeMetrics), b.(*NodeMetrics), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*NodeMetricsList)(nil), (*metrics.NodeMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(a.(*NodeMetricsList), b.(*metrics.NodeMetricsList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*metrics.NodeMetricsList)(nil), (*NodeMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(a.(*metrics.NodeMetricsList), b.(*NodeMetricsList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*PodMetrics)(nil), (*metrics.PodMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_PodMetrics_To_metrics_PodMetrics(a.(*PodMetrics), b.(*metrics.PodMetrics), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*metrics.PodMetrics)(nil), (*PodMetrics)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_metrics_PodMetrics_To_v1alpha1_PodMetrics(a.(*metrics.PodMetrics), b.(*PodMetrics), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*PodMetricsList)(nil), (*metrics.PodMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(a.(*PodMetricsList), b.(*metrics.PodMetricsList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*metrics.PodMetricsList)(nil), (*PodMetricsList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(a.(*metrics.PodMetricsList), b.(*PodMetricsList), scope) + }); err != nil { + return err + } + return nil +} + +func autoConvert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(in *ContainerMetrics, out *metrics.ContainerMetrics, s conversion.Scope) error { + out.Name = in.Name + out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage)) + return nil +} + +// Convert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics is an autogenerated conversion function. +func Convert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(in *ContainerMetrics, out *metrics.ContainerMetrics, s conversion.Scope) error { + return autoConvert_v1alpha1_ContainerMetrics_To_metrics_ContainerMetrics(in, out, s) +} + +func autoConvert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(in *metrics.ContainerMetrics, out *ContainerMetrics, s conversion.Scope) error { + out.Name = in.Name + out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage)) + return nil +} + +// Convert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics is an autogenerated conversion function. +func Convert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(in *metrics.ContainerMetrics, out *ContainerMetrics, s conversion.Scope) error { + return autoConvert_metrics_ContainerMetrics_To_v1alpha1_ContainerMetrics(in, out, s) +} + +func autoConvert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(in *NodeMetrics, out *metrics.NodeMetrics, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.Timestamp = in.Timestamp + out.Window = in.Window + out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage)) + return nil +} + +// Convert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics is an autogenerated conversion function. +func Convert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(in *NodeMetrics, out *metrics.NodeMetrics, s conversion.Scope) error { + return autoConvert_v1alpha1_NodeMetrics_To_metrics_NodeMetrics(in, out, s) +} + +func autoConvert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(in *metrics.NodeMetrics, out *NodeMetrics, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.Timestamp = in.Timestamp + out.Window = in.Window + out.Usage = *(*v1.ResourceList)(unsafe.Pointer(&in.Usage)) + return nil +} + +// Convert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics is an autogenerated conversion function. +func Convert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(in *metrics.NodeMetrics, out *NodeMetrics, s conversion.Scope) error { + return autoConvert_metrics_NodeMetrics_To_v1alpha1_NodeMetrics(in, out, s) +} + +func autoConvert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(in *NodeMetricsList, out *metrics.NodeMetricsList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]metrics.NodeMetrics)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList is an autogenerated conversion function. +func Convert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(in *NodeMetricsList, out *metrics.NodeMetricsList, s conversion.Scope) error { + return autoConvert_v1alpha1_NodeMetricsList_To_metrics_NodeMetricsList(in, out, s) +} + +func autoConvert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(in *metrics.NodeMetricsList, out *NodeMetricsList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]NodeMetrics)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList is an autogenerated conversion function. +func Convert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(in *metrics.NodeMetricsList, out *NodeMetricsList, s conversion.Scope) error { + return autoConvert_metrics_NodeMetricsList_To_v1alpha1_NodeMetricsList(in, out, s) +} + +func autoConvert_v1alpha1_PodMetrics_To_metrics_PodMetrics(in *PodMetrics, out *metrics.PodMetrics, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.Timestamp = in.Timestamp + out.Window = in.Window + out.Containers = *(*[]metrics.ContainerMetrics)(unsafe.Pointer(&in.Containers)) + return nil +} + +// Convert_v1alpha1_PodMetrics_To_metrics_PodMetrics is an autogenerated conversion function. +func Convert_v1alpha1_PodMetrics_To_metrics_PodMetrics(in *PodMetrics, out *metrics.PodMetrics, s conversion.Scope) error { + return autoConvert_v1alpha1_PodMetrics_To_metrics_PodMetrics(in, out, s) +} + +func autoConvert_metrics_PodMetrics_To_v1alpha1_PodMetrics(in *metrics.PodMetrics, out *PodMetrics, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + out.Timestamp = in.Timestamp + out.Window = in.Window + out.Containers = *(*[]ContainerMetrics)(unsafe.Pointer(&in.Containers)) + return nil +} + +// Convert_metrics_PodMetrics_To_v1alpha1_PodMetrics is an autogenerated conversion function. +func Convert_metrics_PodMetrics_To_v1alpha1_PodMetrics(in *metrics.PodMetrics, out *PodMetrics, s conversion.Scope) error { + return autoConvert_metrics_PodMetrics_To_v1alpha1_PodMetrics(in, out, s) +} + +func autoConvert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(in *PodMetricsList, out *metrics.PodMetricsList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]metrics.PodMetrics)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList is an autogenerated conversion function. +func Convert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(in *PodMetricsList, out *metrics.PodMetricsList, s conversion.Scope) error { + return autoConvert_v1alpha1_PodMetricsList_To_metrics_PodMetricsList(in, out, s) +} + +func autoConvert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(in *metrics.PodMetricsList, out *PodMetricsList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]PodMetrics)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList is an autogenerated conversion function. +func Convert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(in *metrics.PodMetricsList, out *PodMetricsList, s conversion.Scope) error { + return autoConvert_metrics_PodMetricsList_To_v1alpha1_PodMetricsList(in, out, s) +} diff --git a/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.deepcopy.go b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 000000000..9cd8619ec --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/apis/metrics/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,186 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "k8s.io/api/core/v1" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ContainerMetrics) DeepCopyInto(out *ContainerMetrics) { + *out = *in + if in.Usage != nil { + in, out := &in.Usage, &out.Usage + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerMetrics. +func (in *ContainerMetrics) DeepCopy() *ContainerMetrics { + if in == nil { + return nil + } + out := new(ContainerMetrics) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeMetrics) DeepCopyInto(out *NodeMetrics) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Timestamp.DeepCopyInto(&out.Timestamp) + out.Window = in.Window + if in.Usage != nil { + in, out := &in.Usage, &out.Usage + *out = make(v1.ResourceList, len(*in)) + for key, val := range *in { + (*out)[key] = val.DeepCopy() + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetrics. +func (in *NodeMetrics) DeepCopy() *NodeMetrics { + if in == nil { + return nil + } + out := new(NodeMetrics) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeMetrics) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NodeMetricsList) DeepCopyInto(out *NodeMetricsList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NodeMetrics, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeMetricsList. +func (in *NodeMetricsList) DeepCopy() *NodeMetricsList { + if in == nil { + return nil + } + out := new(NodeMetricsList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NodeMetricsList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodMetrics) DeepCopyInto(out *PodMetrics) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Timestamp.DeepCopyInto(&out.Timestamp) + out.Window = in.Window + if in.Containers != nil { + in, out := &in.Containers, &out.Containers + *out = make([]ContainerMetrics, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetrics. +func (in *PodMetrics) DeepCopy() *PodMetrics { + if in == nil { + return nil + } + out := new(PodMetrics) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PodMetrics) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PodMetricsList) DeepCopyInto(out *PodMetricsList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PodMetrics, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PodMetricsList. +func (in *PodMetricsList) DeepCopy() *PodMetricsList { + if in == nil { + return nil + } + out := new(PodMetricsList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PodMetricsList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/doc.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/doc.go new file mode 100644 index 000000000..7dc375616 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/register.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/register.go new file mode 100644 index 000000000..a92b020a9 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/scheme/register.go @@ -0,0 +1,58 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + metricsv1alpha1 "k8s.io/metrics/pkg/apis/metrics/v1alpha1" + metricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) +var localSchemeBuilder = runtime.SchemeBuilder{ + metricsv1alpha1.AddToScheme, + metricsv1beta1.AddToScheme, +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +var AddToScheme = localSchemeBuilder.AddToScheme + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + utilruntime.Must(AddToScheme(Scheme)) +} diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/doc.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/doc.go new file mode 100644 index 000000000..771101956 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/doc.go @@ -0,0 +1,20 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1beta1 diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/generated_expansion.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/generated_expansion.go new file mode 100644 index 000000000..a89ca3c78 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/generated_expansion.go @@ -0,0 +1,23 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +type NodeMetricsExpansion interface{} + +type PodMetricsExpansion interface{} diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/metrics_client.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/metrics_client.go new file mode 100644 index 000000000..7a02cea2e --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/metrics_client.go @@ -0,0 +1,112 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "net/http" + + rest "k8s.io/client-go/rest" + v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" + "k8s.io/metrics/pkg/client/clientset/versioned/scheme" +) + +type MetricsV1beta1Interface interface { + RESTClient() rest.Interface + NodeMetricsesGetter + PodMetricsesGetter +} + +// MetricsV1beta1Client is used to interact with features provided by the metrics.k8s.io group. +type MetricsV1beta1Client struct { + restClient rest.Interface +} + +func (c *MetricsV1beta1Client) NodeMetricses() NodeMetricsInterface { + return newNodeMetricses(c) +} + +func (c *MetricsV1beta1Client) PodMetricses(namespace string) PodMetricsInterface { + return newPodMetricses(c, namespace) +} + +// NewForConfig creates a new MetricsV1beta1Client for the given config. +// NewForConfig is equivalent to NewForConfigAndClient(c, httpClient), +// where httpClient was generated with rest.HTTPClientFor(c). +func NewForConfig(c *rest.Config) (*MetricsV1beta1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + httpClient, err := rest.HTTPClientFor(&config) + if err != nil { + return nil, err + } + return NewForConfigAndClient(&config, httpClient) +} + +// NewForConfigAndClient creates a new MetricsV1beta1Client for the given config and http client. +// Note the http client provided takes precedence over the configured transport values. +func NewForConfigAndClient(c *rest.Config, h *http.Client) (*MetricsV1beta1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientForConfigAndClient(&config, h) + if err != nil { + return nil, err + } + return &MetricsV1beta1Client{client}, nil +} + +// NewForConfigOrDie creates a new MetricsV1beta1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *MetricsV1beta1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new MetricsV1beta1Client for the given RESTClient. +func New(c rest.Interface) *MetricsV1beta1Client { + return &MetricsV1beta1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1beta1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *MetricsV1beta1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/nodemetrics.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/nodemetrics.go new file mode 100644 index 000000000..a312221ed --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/nodemetrics.go @@ -0,0 +1,98 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" + scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" +) + +// NodeMetricsesGetter has a method to return a NodeMetricsInterface. +// A group's client should implement this interface. +type NodeMetricsesGetter interface { + NodeMetricses() NodeMetricsInterface +} + +// NodeMetricsInterface has methods to work with NodeMetrics resources. +type NodeMetricsInterface interface { + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.NodeMetrics, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.NodeMetricsList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + NodeMetricsExpansion +} + +// nodeMetricses implements NodeMetricsInterface +type nodeMetricses struct { + client rest.Interface +} + +// newNodeMetricses returns a NodeMetricses +func newNodeMetricses(c *MetricsV1beta1Client) *nodeMetricses { + return &nodeMetricses{ + client: c.RESTClient(), + } +} + +// Get takes name of the nodeMetrics, and returns the corresponding nodeMetrics object, and an error if there is any. +func (c *nodeMetricses) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.NodeMetrics, err error) { + result = &v1beta1.NodeMetrics{} + err = c.client.Get(). + Resource("nodes"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of NodeMetricses that match those selectors. +func (c *nodeMetricses) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.NodeMetricsList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.NodeMetricsList{} + err = c.client.Get(). + Resource("nodes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested nodeMetricses. +func (c *nodeMetricses) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Resource("nodes"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} diff --git a/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/podmetrics.go b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/podmetrics.go new file mode 100644 index 000000000..e66c377c2 --- /dev/null +++ b/vendor/k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1/podmetrics.go @@ -0,0 +1,103 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1beta1 + +import ( + "context" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + v1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1" + scheme "k8s.io/metrics/pkg/client/clientset/versioned/scheme" +) + +// PodMetricsesGetter has a method to return a PodMetricsInterface. +// A group's client should implement this interface. +type PodMetricsesGetter interface { + PodMetricses(namespace string) PodMetricsInterface +} + +// PodMetricsInterface has methods to work with PodMetrics resources. +type PodMetricsInterface interface { + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.PodMetrics, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.PodMetricsList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + PodMetricsExpansion +} + +// podMetricses implements PodMetricsInterface +type podMetricses struct { + client rest.Interface + ns string +} + +// newPodMetricses returns a PodMetricses +func newPodMetricses(c *MetricsV1beta1Client, namespace string) *podMetricses { + return &podMetricses{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the podMetrics, and returns the corresponding podMetrics object, and an error if there is any. +func (c *podMetricses) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.PodMetrics, err error) { + result = &v1beta1.PodMetrics{} + err = c.client.Get(). + Namespace(c.ns). + Resource("pods"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of PodMetricses that match those selectors. +func (c *podMetricses) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.PodMetricsList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.PodMetricsList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("pods"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested podMetricses. +func (c *podMetricses) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("pods"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index f27d35a68..8ddb56ae1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1686,7 +1686,10 @@ k8s.io/kubernetes/pkg/apis/storage/util # k8s.io/metrics v0.28.1 ## explicit; go 1.20 k8s.io/metrics/pkg/apis/metrics +k8s.io/metrics/pkg/apis/metrics/v1alpha1 k8s.io/metrics/pkg/apis/metrics/v1beta1 +k8s.io/metrics/pkg/client/clientset/versioned/scheme +k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1 # k8s.io/pod-security-admission v0.28.1 ## explicit; go 1.20 k8s.io/pod-security-admission/admission From 05b917e1730b2b365bdc51e282e8aff5d3b4e1b8 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Thu, 9 Nov 2023 12:36:07 +0530 Subject: [PATCH 14/17] add tests for metrics proxy - node and pod metrics enable hostNetwork for metrics server Signed-off-by: Ishan Khare --- .github/workflows/e2e.yaml | 2 +- pkg/controllers/resources/pods/syncer_test.go | 4 ++ pkg/server/filters/metrics_server.go | 16 +++++++- test/e2e_metrics_proxy/metricsProxy.go | 37 ++++++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index fbcdbbc59..415ba7a59 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -211,7 +211,7 @@ jobs: 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 defaultArgs={--kubelet-insecure-tls} -n kube-system + helm upgrade --install metrics-server metrics-server/metrics-server --set defaultArgs={--kubelet-insecure-tls} --set hostNetwork.enabled=true -n kube-system - name: Wait until vcluster is ready id: wait-until-vcluster-is-ready diff --git a/pkg/controllers/resources/pods/syncer_test.go b/pkg/controllers/resources/pods/syncer_test.go index cc478f794..744b59825 100644 --- a/pkg/controllers/resources/pods/syncer_test.go +++ b/pkg/controllers/resources/pods/syncer_test.go @@ -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" @@ -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" diff --git a/pkg/server/filters/metrics_server.go b/pkg/server/filters/metrics_server.go index 2cfd9842a..55b912b39 100644 --- a/pkg/server/filters/metrics_server.go +++ b/pkg/server/filters/metrics_server.go @@ -517,13 +517,27 @@ func (p *MetricsServerProxy) rewritePodMetricsListData(data []byte) ([]byte, err func getVirtualPodObjectsInNamespace(ctx context.Context, vClient client.Client, namespace string) ([]corev1.Pod, error) { podList := &corev1.PodList{} + // This is to counter an issue which occurred after the latest update + // to 0.28 client libraries where the cache api was changed and broke + // our cachedClients resulting in errors of the form + // "unable to list: kube-system because of unknown namespace for the cache" err := vClient.List(ctx, podList, &client.ListOptions{ - Namespace: namespace, + // Namespace: namespace, }) if err != nil { return nil, err } + // manually filter until the above issue with cachedClient is resolved + filteredPodList := &corev1.PodList{} + for _, pod := range podList.Items { + if pod.Namespace == namespace { + filteredPodList.Items = append(filteredPodList.Items, pod) + } + } + + podList.Items = filteredPodList.Items + return podList.Items, nil } diff --git a/test/e2e_metrics_proxy/metricsProxy.go b/test/e2e_metrics_proxy/metricsProxy.go index b54f0ae04..3893475ee 100644 --- a/test/e2e_metrics_proxy/metricsProxy.go +++ b/test/e2e_metrics_proxy/metricsProxy.go @@ -2,6 +2,7 @@ package e2emetricsproxy import ( "context" + "fmt" "time" "github.com/loft-sh/vcluster/pkg/metricsapiservice" @@ -12,13 +13,15 @@ import ( "k8s.io/apimachinery/pkg/util/wait" apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" apiregistrationv1clientset "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1" + + metricsv1beta1client "k8s.io/metrics/pkg/client/clientset/versioned/typed/metrics/v1beta1" ) var _ = ginkgo.Describe("Target Namespace", func() { f := framework.DefaultFramework ginkgo.It("Make sure the metrics api service is registered and available", func() { - err := wait.PollUntilContextTimeout(f.Context, time.Second, time.Minute*1, false, func(ctx context.Context) (done bool, err error) { + err := wait.PollUntilContextTimeout(f.Context, time.Second, time.Minute*1, false, func(ctx context.Context) (bool, error) { apiRegistrationClient := apiregistrationv1clientset.NewForConfigOrDie(f.VclusterConfig) apiService, err := apiRegistrationClient.APIServices().Get(f.Context, metricsapiservice.MetricsAPIServiceName, metav1.GetOptions{}) if err != nil { @@ -33,4 +36,36 @@ var _ = ginkgo.Describe("Target Namespace", func() { }) framework.ExpectNoError(err) }) + + ginkgo.It("Make sure get nodeMetrics and podMetrics succeed", func() { + err := wait.PollUntilContextTimeout(f.Context, time.Second, time.Minute*1, false, func(ctx context.Context) (bool, error) { + metricsClient := metricsv1beta1client.NewForConfigOrDie(f.VclusterConfig) + + nodeMetricsList, err := metricsClient.NodeMetricses().List(f.Context, metav1.ListOptions{}) + if err != nil { + fmt.Fprintf(ginkgo.GinkgoWriter, "error getting node metrics list %v", err) + return false, nil + } + + if len(nodeMetricsList.Items) == 0 { + fmt.Fprintf(ginkgo.GinkgoWriter, "expecting node metrics list to have at least 1 entry, got %d", len(nodeMetricsList.Items)) + return false, nil + } + + podMetricsList, err := metricsClient.PodMetricses("kube-system").List(f.Context, metav1.ListOptions{}) + if err != nil { + fmt.Fprintf(ginkgo.GinkgoWriter, "error getting pod metrics list %v", err) + return false, nil + } + + if len(podMetricsList.Items) == 0 { + fmt.Fprintf(ginkgo.GinkgoWriter, "expecting pod metrics list to have at least 1 entry, got %d", len(podMetricsList.Items)) + return false, nil + } + + return true, nil + }) + + framework.ExpectNoError(err) + }) }) From c6d0d85d95325c0f1aeeb34d7f297039a004c570 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Thu, 9 Nov 2023 17:50:54 +0530 Subject: [PATCH 15/17] fix metrics server chart installation Signed-off-by: Ishan Khare --- .github/workflows/e2e.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 415ba7a59..a2b6e16e0 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -211,7 +211,7 @@ jobs: 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 defaultArgs={--kubelet-insecure-tls} --set hostNetwork.enabled=true -n kube-system + 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 From 438d8acf6b7229f69ec55cece02e7e0db85a5970 Mon Sep 17 00:00:00 2001 From: Ishan Khare Date: Tue, 14 Nov 2023 22:21:09 +0530 Subject: [PATCH 16/17] remove single bin flag, utilize existing distro detection mechanism Signed-off-by: Ishan Khare --- charts/eks/templates/syncer-deployment.yaml | 1 - charts/k8s/templates/syncer-deployment.yaml | 1 - pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go | 8 ++++---- pkg/controllers/resources/endpoints/syncer.go | 2 ++ pkg/controllers/resources/services/syncer.go | 4 +--- pkg/metricsapiservice/register.go | 4 ++-- pkg/server/cert/cert.go | 4 ++-- pkg/server/cert/syncer.go | 6 +++--- pkg/setup/initialize.go | 1 + pkg/setup/options/flags.go | 1 - pkg/setup/options/options.go | 2 +- pkg/specialservices/resolver.go | 6 +++--- 12 files changed, 19 insertions(+), 21 deletions(-) diff --git a/charts/eks/templates/syncer-deployment.yaml b/charts/eks/templates/syncer-deployment.yaml index e1b4b93b1..499251483 100644 --- a/charts/eks/templates/syncer-deployment.yaml +++ b/charts/eks/templates/syncer-deployment.yaml @@ -169,7 +169,6 @@ spec: {{- end }} {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled}} - --proxy-metrics-server=true - - --single-binary-distro=false {{- end }} {{- if .Values.coredns.integrated }} - --integrated-coredns=true diff --git a/charts/k8s/templates/syncer-deployment.yaml b/charts/k8s/templates/syncer-deployment.yaml index d6fec6fd9..721f7e631 100644 --- a/charts/k8s/templates/syncer-deployment.yaml +++ b/charts/k8s/templates/syncer-deployment.yaml @@ -202,7 +202,6 @@ spec: {{- end }} {{- if or .Values.proxy.metricsServer.nodes.enabled .Values.proxy.metricsServer.pods.enabled }} - --proxy-metrics-server=true - - --single-binary-distro=false {{- end }} {{- if .Values.coredns.integrated }} - --integrated-coredns=true diff --git a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go index c3d6009c8..00d685309 100644 --- a/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go +++ b/pkg/controllers/k8sdefaultendpoint/k8sdefaultendpoint.go @@ -42,7 +42,7 @@ type EndpointController struct { provider provider - singleBinaryDistro bool + k8sDistro bool } func NewEndpointController(ctx *options.ControllerContext, provider provider) *EndpointController { @@ -54,7 +54,7 @@ func NewEndpointController(ctx *options.ControllerContext, provider provider) *E VirtualManagerCache: ctx.VirtualManager.GetCache(), Log: loghelper.New("kubernetes-default-endpoint-controller"), provider: provider, - singleBinaryDistro: ctx.Options.SingleBinaryDistro, + k8sDistro: ctx.Options.IsK8sDistro, } } @@ -72,7 +72,7 @@ func (e *EndpointController) Reconcile(ctx context.Context, _ ctrl.Request) (ctr return ctrl.Result{RequeueAfter: time.Second}, err } - if !e.singleBinaryDistro { + 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 @@ -94,7 +94,7 @@ func (e *EndpointController) SetupWithManager(mgr ctrl.Manager) error { return true } - if !e.singleBinaryDistro { + if e.k8sDistro { if object.GetNamespace() == specialservices.VclusterProxyMetricsSvcKey.Namespace && object.GetName() == specialservices.VclusterProxyMetricsSvcKey.Name { return true diff --git a/pkg/controllers/resources/endpoints/syncer.go b/pkg/controllers/resources/endpoints/syncer.go index 280ae435e..1062d967b 100644 --- a/pkg/controllers/resources/endpoints/syncer.go +++ b/pkg/controllers/resources/endpoints/syncer.go @@ -42,6 +42,8 @@ var _ syncer.Starter = &endpointsSyncer{} func (s *endpointsSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.Request) (bool, error) { if req.NamespacedName == specialservices.DefaultKubernetesSvcKey { return true, nil + } else if _, ok := specialservices.Default.SpecialServicesToSync()[req.NamespacedName]; ok { + return true, nil } svc := &corev1.Service{} diff --git a/pkg/controllers/resources/services/syncer.go b/pkg/controllers/resources/services/syncer.go index 68d7cd346..986f24c2c 100644 --- a/pkg/controllers/resources/services/syncer.go +++ b/pkg/controllers/resources/services/syncer.go @@ -157,9 +157,7 @@ var _ syncertypes.Starter = &serviceSyncer{} func (s *serviceSyncer) ReconcileStart(ctx *synccontext.SyncContext, req ctrl.Request) (bool, error) { // don't do anything for the kubernetes service specialServices := specialservices.Default.SpecialServicesToSync() - - svc, ok := specialServices[req.NamespacedName] - if ok { + if svc, ok := specialServices[req.NamespacedName]; ok { return true, svc(ctx, ctx.CurrentNamespace, s.serviceName, req.NamespacedName, TranslateServicePorts) } diff --git a/pkg/metricsapiservice/register.go b/pkg/metricsapiservice/register.go index c02b1c3f8..3a5ee0022 100644 --- a/pkg/metricsapiservice/register.go +++ b/pkg/metricsapiservice/register.go @@ -65,7 +65,7 @@ func applyOperation(ctx context.Context, operationFunc wait.ConditionWithContext func deleteOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithContextFunc { return func(ctx context.Context) (bool, error) { - if !ctrlCtx.Options.SingleBinaryDistro { + if ctrlCtx.Options.IsK8sDistro { auxVirtualSvc := &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: AuxVirtualSvcName, @@ -120,7 +120,7 @@ func createOperation(ctrlCtx *options.ControllerContext) wait.ConditionWithConte VersionPriority: 100, } - if !ctrlCtx.Options.SingleBinaryDistro { + if ctrlCtx.Options.IsK8sDistro { // in this case we register an apiservice with a service reference object // this service is created as a special service and the physical-virtual // pair makes sure the service discovery happens as expected in even non single diff --git a/pkg/server/cert/cert.go b/pkg/server/cert/cert.go index a4db7efec..6d6caf18f 100644 --- a/pkg/server/cert/cert.go +++ b/pkg/server/cert/cert.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/util/sets" ) -func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byte, clusterDomain string, SANs []string, isSingleBinaryDistro bool) ([]byte, []byte, bool, error) { +func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byte, clusterDomain string, SANs []string, k8sDistro bool) ([]byte, []byte, bool, error) { regen := false commonName := "kube-apiserver" extKeyUsage := []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth} @@ -24,7 +24,7 @@ func GenServingCerts(caCertFile, caKeyFile string, currentCert, currentKey []byt "localhost", } - if !isSingleBinaryDistro { + if k8sDistro { dnsNames = append(dnsNames, []string{ "metrics-server.kube-system.svc." + clusterDomain, "metrics-server.kube-system.svc", diff --git a/pkg/server/cert/syncer.go b/pkg/server/cert/syncer.go index 868d9a7fe..eb9037711 100644 --- a/pkg/server/cert/syncer.go +++ b/pkg/server/cert/syncer.go @@ -45,7 +45,7 @@ func NewSyncer(_ context.Context, currentNamespace string, currentNamespaceClien currentNamespace: currentNamespace, currentNamespaceCient: currentNamespaceClient, - isSingleBinaryDistro: options.SingleBinaryDistro, + k8sDistro: options.IsK8sDistro, }, nil } @@ -70,7 +70,7 @@ type syncer struct { currentKey []byte currentSANs []string - isSingleBinaryDistro bool + k8sDistro bool } func (s *syncer) Name() string { @@ -199,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, s.isSingleBinaryDistro) + cert, key, _, err := GenServingCerts(s.serverCaCert, s.serverCaKey, s.currentCert, s.currentKey, s.clusterDomain, extraSANs, s.k8sDistro) if err != nil { return err } diff --git a/pkg/setup/initialize.go b/pkg/setup/initialize.go index 0187d0203..f0ba749f6 100644 --- a/pkg/setup/initialize.go +++ b/pkg/setup/initialize.go @@ -116,6 +116,7 @@ func initialize( } }() } else if certificatesDir != "" { + options.IsK8sDistro = true err = GenerateK8sCerts(ctx, currentNamespaceClient, vClusterName, currentNamespace, serviceCIDR, certificatesDir, options.ClusterDomain) if err != nil { return err diff --git a/pkg/setup/options/flags.go b/pkg/setup/options/flags.go index ae60ddffa..eb43817f3 100644 --- a/pkg/setup/options/flags.go +++ b/pkg/setup/options/flags.go @@ -61,7 +61,6 @@ func AddFlags(flags *pflag.FlagSet, options *VirtualClusterOptions) { flags.StringVar(&options.HostMetricsBindAddress, "host-metrics-bind-address", "0", "If set, metrics for the controller manager for the resources managed in the host cluster will be exposed at this address") flags.StringVar(&options.VirtualMetricsBindAddress, "virtual-metrics-bind-address", "0", "If set, metrics for the controller manager for the resources managed in the virtual cluster will be exposed at this address") - flags.BoolVar(&options.SingleBinaryDistro, "single-binary-distro", true, "Indicates vcluster wether the distro used is single binary (k3s/k0s) or k8s/eks") flags.BoolVar(&options.MountPhysicalHostPaths, "mount-physical-host-paths", false, "If enabled, syncer will rewite hostpaths in synced pod volumes") flags.BoolVar(&options.MultiNamespaceMode, "multi-namespace-mode", false, "If enabled, syncer will create a namespace for each virtual namespace and use the original names for the synced namespaced resources") flags.StringSliceVar(&options.NamespaceLabels, "namespace-labels", []string{}, "Defines one or more labels that will be added to the namespaces synced in the multi-namespace mode. Format: \"labelKey=labelValue\". Multiple values can be passed in a comma-separated string.") diff --git a/pkg/setup/options/options.go b/pkg/setup/options/options.go index 9a9641286..7be84b762 100644 --- a/pkg/setup/options/options.go +++ b/pkg/setup/options/options.go @@ -66,7 +66,7 @@ type VirtualClusterOptions struct { SyncLabels []string `json:"syncLabels,omitempty"` - SingleBinaryDistro bool `json:"singleBinaryDistro,omitempty"` + IsK8sDistro bool `json:"singleBinaryDistro,omitempty"` // hostpath mapper options // this is only needed if using vcluster-hostpath-mapper component diff --git a/pkg/specialservices/resolver.go b/pkg/specialservices/resolver.go index dd784d04f..9fe42fb44 100644 --- a/pkg/specialservices/resolver.go +++ b/pkg/specialservices/resolver.go @@ -11,7 +11,7 @@ import ( var Default Interface func SetDefault(ctrlCtx *options.VirtualClusterOptions) { - Default = defaultNameserverFinder(ctrlCtx.SingleBinaryDistro) + Default = defaultNameserverFinder(ctrlCtx.IsK8sDistro) } const ( @@ -46,12 +46,12 @@ func (f *NameserverFinder) SpecialServicesToSync() map[types.NamespacedName]Spec return f.SpecialServices } -func defaultNameserverFinder(isSingleBinaryDistro bool) Interface { +func defaultNameserverFinder(k8sDistro bool) Interface { specialServicesMap := map[types.NamespacedName]SpecialServiceSyncer{ DefaultKubernetesSvcKey: SyncKubernetesService, } - if !isSingleBinaryDistro { + if k8sDistro { specialServicesMap[VclusterProxyMetricsSvcKey] = SyncVclusterProxyService } From f742c4e84a84ceeaa9a6299fbd51e068652e879d Mon Sep 17 00:00:00 2001 From: Fabian Kramm Date: Wed, 15 Nov 2023 13:14:38 +0100 Subject: [PATCH 17/17] refactor: use cache correctly --- pkg/server/filters/metrics_server.go | 17 +---------------- pkg/server/server.go | 15 ++++++++++----- pkg/specialservices/resolver.go | 2 -- 3 files changed, 11 insertions(+), 23 deletions(-) diff --git a/pkg/server/filters/metrics_server.go b/pkg/server/filters/metrics_server.go index 55b912b39..2c20c6355 100644 --- a/pkg/server/filters/metrics_server.go +++ b/pkg/server/filters/metrics_server.go @@ -516,28 +516,13 @@ func (p *MetricsServerProxy) rewritePodMetricsListData(data []byte) ([]byte, err // returns the types.NamespacedName list of pods for the given namespace func getVirtualPodObjectsInNamespace(ctx context.Context, vClient client.Client, namespace string) ([]corev1.Pod, error) { podList := &corev1.PodList{} - - // This is to counter an issue which occurred after the latest update - // to 0.28 client libraries where the cache api was changed and broke - // our cachedClients resulting in errors of the form - // "unable to list: kube-system because of unknown namespace for the cache" err := vClient.List(ctx, podList, &client.ListOptions{ - // Namespace: namespace, + Namespace: namespace, }) if err != nil { return nil, err } - // manually filter until the above issue with cachedClient is resolved - filteredPodList := &corev1.PodList{} - for _, pod := range podList.Items { - if pod.Namespace == namespace { - filteredPodList.Items = append(filteredPodList.Items, pod) - } - } - - podList.Items = filteredPodList.Items - return podList.Items, nil } diff --git a/pkg/server/server.go b/pkg/server/server.go index c98ecc754..2ca3bcba4 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -296,12 +296,17 @@ func (s *Server) ServeOnListenerTLS(address string, port int, stopChan <-chan st } func createCachedClient(ctx context.Context, config *rest.Config, namespace string, restMapper meta.RESTMapper, scheme *runtime.Scheme, registerIndices func(cache cache.Cache) error) (client.Client, error) { + // create cache options + cacheOptions := cache.Options{ + Scheme: scheme, + Mapper: restMapper, + } + if namespace != "" { + cacheOptions.DefaultNamespaces = map[string]cache.Config{namespace: {}} + } + // create the new cache - clientCache, err := cache.New(config, cache.Options{ - Scheme: scheme, - Mapper: restMapper, - DefaultNamespaces: map[string]cache.Config{namespace: {}}, - }) + clientCache, err := cache.New(config, cacheOptions) if err != nil { return nil, err } diff --git a/pkg/specialservices/resolver.go b/pkg/specialservices/resolver.go index 9fe42fb44..dbb12d0f8 100644 --- a/pkg/specialservices/resolver.go +++ b/pkg/specialservices/resolver.go @@ -17,8 +17,6 @@ func SetDefault(ctrlCtx *options.VirtualClusterOptions) { const ( DefaultKubeDNSServiceName = "kube-dns" DefaultKubeDNSServiceNamespace = "kube-system" - - DistroEnvKey = "SINGLE_BINARY_DISTRO" ) type SpecialServiceSyncer func(