Skip to content

Commit

Permalink
Merge pull request #3578 from jwcesign/metrics-adapter-v4
Browse files Browse the repository at this point in the history
feat: add metrics-adapter component to support centralized hpa
  • Loading branch information
karmada-bot committed May 28, 2023
2 parents 93cefe4 + 6dfa4d0 commit 4235569
Show file tree
Hide file tree
Showing 187 changed files with 32,110 additions and 1,081 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ TARGETS := karmada-aggregated-apiserver \
karmada-scheduler-estimator \
karmada-interpreter-webhook-example \
karmada-search \
karmada-operator
karmada-operator \
karmada-metrics-adapter

CTL_TARGETS := karmadactl kubectl-karmada

Expand Down Expand Up @@ -122,6 +123,7 @@ endif
docker push ${REGISTRY}/karmada-aggregated-apiserver:${VERSION}
docker push ${REGISTRY}/karmada-search:${VERSION}
docker push ${REGISTRY}/karmada-operator:${VERSION}
docker push ${REGISTRY}/karmada-metrics-adapter:${VERSION}

# Build and package binary
#
Expand Down
37 changes: 21 additions & 16 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"version": "unversioned"
},
"paths": {
"/apis/": {
"/apis": {
"get": {
"description": "get available API versions",
"consumes": [
Expand Down Expand Up @@ -40,7 +40,7 @@
}
}
},
"/apis/cluster.karmada.io/": {
"/apis/cluster.karmada.io": {
"get": {
"description": "get information of a group",
"consumes": [
Expand Down Expand Up @@ -70,7 +70,7 @@
}
}
},
"/apis/cluster.karmada.io/v1alpha1/": {
"/apis/cluster.karmada.io/v1alpha1": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -1564,7 +1564,7 @@
}
]
},
"/apis/config.karmada.io/": {
"/apis/config.karmada.io": {
"get": {
"description": "get information of a group",
"consumes": [
Expand Down Expand Up @@ -1594,7 +1594,7 @@
}
}
},
"/apis/config.karmada.io/v1alpha1/": {
"/apis/config.karmada.io/v1alpha1": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -2624,7 +2624,7 @@
}
]
},
"/apis/networking.karmada.io/": {
"/apis/networking.karmada.io": {
"get": {
"description": "get information of a group",
"consumes": [
Expand Down Expand Up @@ -2654,7 +2654,7 @@
}
}
},
"/apis/networking.karmada.io/v1alpha1/": {
"/apis/networking.karmada.io/v1alpha1": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -3940,7 +3940,7 @@
}
]
},
"/apis/policy.karmada.io/": {
"/apis/policy.karmada.io": {
"get": {
"description": "get information of a group",
"consumes": [
Expand Down Expand Up @@ -3970,7 +3970,7 @@
}
}
},
"/apis/policy.karmada.io/v1alpha1/": {
"/apis/policy.karmada.io/v1alpha1": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -9768,7 +9768,7 @@
}
]
},
"/apis/search.karmada.io/": {
"/apis/search.karmada.io": {
"get": {
"description": "get information of a group",
"consumes": [
Expand Down Expand Up @@ -9798,7 +9798,7 @@
}
}
},
"/apis/search.karmada.io/v1alpha1/": {
"/apis/search.karmada.io/v1alpha1": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -10828,7 +10828,7 @@
}
]
},
"/apis/work.karmada.io/": {
"/apis/work.karmada.io": {
"get": {
"description": "get information of a group",
"consumes": [
Expand Down Expand Up @@ -10858,7 +10858,7 @@
}
}
},
"/apis/work.karmada.io/v1alpha1/": {
"/apis/work.karmada.io/v1alpha1": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -12144,7 +12144,7 @@
}
]
},
"/apis/work.karmada.io/v1alpha2/": {
"/apis/work.karmada.io/v1alpha2": {
"get": {
"description": "get available resources",
"consumes": [
Expand Down Expand Up @@ -17081,8 +17081,13 @@
"type": "string"
},
"pathType": {
"description": "PathType determines the interpretation of the Path matching. PathType can be one of the following values: * Exact: Matches the URL path exactly. * Prefix: Matches based on a URL path prefix split by '/'. Matching is\n done on a path element by element basis. A path element refers is the\n list of labels in the path split by the '/' separator. A request is a\n match for path p if every p is an element-wise prefix of p of the\n request path. Note that if the last element of the path is a substring\n of the last element in request path, it is not a match (e.g. /foo/bar\n matches /foo/bar/baz, but does not match /foo/barbaz).\n* ImplementationSpecific: Interpretation of the Path matching is up to\n the IngressClass. Implementations can treat this as a separate PathType\n or treat it identically to Prefix or Exact path types.\nImplementations are required to support all path types.",
"type": "string"
"description": "PathType determines the interpretation of the Path matching. PathType can be one of the following values: * Exact: Matches the URL path exactly. * Prefix: Matches based on a URL path prefix split by '/'. Matching is\n done on a path element by element basis. A path element refers is the\n list of labels in the path split by the '/' separator. A request is a\n match for path p if every p is an element-wise prefix of p of the\n request path. Note that if the last element of the path is a substring\n of the last element in request path, it is not a match (e.g. /foo/bar\n matches /foo/bar/baz, but does not match /foo/barbaz).\n* ImplementationSpecific: Interpretation of the Path matching is up to\n the IngressClass. Implementations can treat this as a separate PathType\n or treat it identically to Prefix or Exact path types.\nImplementations are required to support all path types.\n\nPossible enum values:\n - `\"Exact\"` matches the URL path exactly and with case sensitivity.\n - `\"ImplementationSpecific\"` matching is up to the IngressClass. Implementations can treat this as a separate PathType or treat it identically to Prefix or Exact path types.\n - `\"Prefix\"` matches based on a URL path prefix split by '/'. Matching is case sensitive and done on a path element by element basis. A path element refers to the list of labels in the path split by the '/' separator. A request is a match for path p if every p is an element-wise prefix of p of the request path. Note that if the last element of the path is a substring of the last element in request path, it is not a match (e.g. /foo/bar matches /foo/bar/baz, but does not match /foo/barbaz). If multiple matching paths exist in an Ingress spec, the longest matching path is given priority. Examples: - /foo/bar does not match requests to /foo/barbaz - /foo/bar matches request to /foo/bar and /foo/bar/baz - /foo and /foo/ both match requests to /foo and /foo/. If both paths are present in an Ingress spec, the longest matching path (/foo/) is given priority.",
"type": "string",
"enum": [
"Exact",
"ImplementationSpecific",
"Prefix"
]
}
}
},
Expand Down
25 changes: 25 additions & 0 deletions artifacts/deploy/karmada-metrics-adapter-apiservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1beta1.metrics.k8s.io
labels:
app: karmada-metrics-adapter
apiserver: "true"
spec:
insecureSkipTLSVerify: true
group: metrics.k8s.io
groupPriorityMinimum: 2000
service:
name: karmada-metrics-adapter
namespace: karmada-system
version: v1beta1
versionPriority: 10
---
apiVersion: v1
kind: Service
metadata:
name: karmada-metrics-adapter
namespace: karmada-system
spec:
type: ExternalName
externalName: karmada-metrics-adapter.karmada-system.svc.cluster.local
86 changes: 86 additions & 0 deletions artifacts/deploy/karmada-metrics-adapter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: karmada-metrics-adapter
namespace: karmada-system
labels:
app: karmada-metrics-adapter
apiserver: "true"
spec:
selector:
matchLabels:
app: karmada-metrics-adapter
apiserver: "true"
replicas: 1
template:
metadata:
labels:
app: karmada-metrics-adapter
apiserver: "true"
spec:
automountServiceAccountToken: false
containers:
- name: karmada-metrics-adapter
image: docker.io/karmada/karmada-metrics-adapter:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- name: karmada-certs
mountPath: /etc/karmada/pki
readOnly: true
- name: kubeconfig
subPath: kubeconfig
mountPath: /etc/kubeconfig
command:
- /bin/karmada-metrics-adapter
- --kubeconfig=/etc/kubeconfig
- --authentication-kubeconfig=/etc/kubeconfig
- --authorization-kubeconfig=/etc/kubeconfig
- --client-ca-file=/etc/karmada/pki/ca.crt
- --audit-log-path=-
- --audit-log-maxage=0
- --audit-log-maxbackup=0
readinessProbe:
httpGet:
path: /readyz
port: 443
scheme: HTTPS
initialDelaySeconds: 1
failureThreshold: 3
periodSeconds: 3
timeoutSeconds: 15
livenessProbe:
httpGet:
path: /healthz
port: 443
scheme: HTTPS
initialDelaySeconds: 10
failureThreshold: 3
periodSeconds: 10
timeoutSeconds: 15
resources:
requests:
cpu: 100m
volumes:
- name: karmada-certs
secret:
secretName: karmada-cert-secret
- name: kubeconfig
secret:
secretName: kubeconfig
---
apiVersion: v1
kind: Service
metadata:
name: karmada-metrics-adapter
namespace: karmada-system
labels:
app: karmada-metrics-adapter
apiserver: "true"
spec:
ports:
- port: 443
protocol: TCP
targetPort: 443
selector:
app: karmada-metrics-adapter
62 changes: 62 additions & 0 deletions cmd/metrics-adapter/app/metrics-adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package app

import (
"context"
"fmt"

"github.com/spf13/cobra"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/term"

"github.com/karmada-io/karmada/cmd/metrics-adapter/app/options"
"github.com/karmada-io/karmada/pkg/sharedcli"
"github.com/karmada-io/karmada/pkg/sharedcli/klogflag"
"github.com/karmada-io/karmada/pkg/version/sharedcommand"
)

// NewMetricsAdapterCommand creates a *cobra.Command object with default parameters
func NewMetricsAdapterCommand(ctx context.Context) *cobra.Command {
opts := options.NewOptions()

cmd := &cobra.Command{
Use: "karmada-metrics-adapter",
Long: `The karmada-metrics-adapter is a adapter to aggregate the metrics from member clusters.`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := opts.Complete(); err != nil {
return err
}
if err := opts.Validate(); err != nil {
return err
}
if err := opts.Run(ctx); err != nil {
return err
}
return nil
},
Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
if len(arg) > 0 {
return fmt.Errorf("%q does not take any arguments, got %q", cmd.CommandPath(), args)
}
}
return nil
},
}

fss := cliflag.NamedFlagSets{}

genericFlagSet := fss.FlagSet("generic")
opts.AddFlags(genericFlagSet)

// Set klog flags
logsFlagSet := fss.FlagSet("logs")
klogflag.Add(logsFlagSet)

cmd.AddCommand(sharedcommand.NewCmdVersion("karmada-metrics-adapter"))
cmd.Flags().AddFlagSet(genericFlagSet)
cmd.Flags().AddFlagSet(logsFlagSet)

cols, _, _ := term.TerminalSize(cmd.OutOrStdout())
sharedcli.SetUsageAndHelpFunc(cmd, fss, cols)
return cmd
}
Loading

0 comments on commit 4235569

Please sign in to comment.