Skip to content

Commit

Permalink
Merge pull request #1903 from FabianKramm/main
Browse files Browse the repository at this point in the history
refactor: integrations & apiservice
  • Loading branch information
FabianKramm committed Jul 8, 2024
2 parents 6b0923b + 35bd4b1 commit 578a390
Show file tree
Hide file tree
Showing 48 changed files with 1,714 additions and 1,325 deletions.
2 changes: 1 addition & 1 deletion chart/templates/_rbac.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
(eq (toString .Values.sync.fromHost.csiDrivers.enabled) "true")
(eq (toString .Values.sync.fromHost.csiStorageCapacities.enabled) "true")
.Values.sync.fromHost.nodes.enabled
.Values.observability.metrics.proxy.nodes
(and .Values.integrations.metricsServer.enabled .Values.integrations.metricsServer.nodes)
.Values.experimental.multiNamespaceMode.enabled -}}
{{- true -}}
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ rules:
resources: ["namespaces", "serviceaccounts"]
verbs: ["create", "delete", "patch", "update", "get", "watch", "list"]
{{- end }}
{{- if .Values.observability.metrics.proxy.nodes }}
{{- if (and .Values.integrations.metricsServer.enabled .Values.integrations.metricsServer.nodes) }}
- apiGroups: ["metrics.k8s.io"]
resources: ["nodes"]
verbs: ["get", "list"]
Expand Down
2 changes: 1 addition & 1 deletion chart/templates/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ rules:
resources: ["leases"]
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
{{- end }}
{{- if .Values.observability.metrics.proxy.pods }}
{{- if (and .Values.integrations.metricsServer.enabled .Values.integrations.metricsServer.pods) }}
- apiGroups: ["metrics.k8s.io"]
resources: ["pods"]
verbs: ["get", "list"]
Expand Down
8 changes: 4 additions & 4 deletions chart/tests/clusterrole_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,10 @@ tests:

- it: metrics proxy
set:
observability:
metrics:
proxy:
nodes: true
integrations:
metricsServer:
enabled: true
nodes: true
release:
name: my-release
namespace: my-namespace
Expand Down
8 changes: 4 additions & 4 deletions chart/tests/role_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ tests:

- it: metrics proxy
set:
observability:
metrics:
proxy:
pods: true
integrations:
metricsServer:
enabled: true
pods: true
release:
name: my-release
namespace: my-namespace
Expand Down
48 changes: 22 additions & 26 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,17 @@
"additionalProperties": false,
"type": "object"
},
"Integrations": {
"properties": {
"metricsServer": {
"$ref": "#/$defs/MetricsServer",
"description": "MetricsServer reuses the metrics server from the host cluster within the vCluster."
}
},
"additionalProperties": false,
"type": "object",
"description": "Integrations holds config for vCluster integrations with other operators or tools running on the host cluster"
},
"LabelsAndAnnotations": {
"properties": {
"annotations": {
Expand Down Expand Up @@ -1725,8 +1736,12 @@
"additionalProperties": false,
"type": "object"
},
"MetricsProxy": {
"MetricsServer": {
"properties": {
"enabled": {
"type": "boolean",
"description": "Enabled signals the metrics server integration should be enabled."
},
"nodes": {
"type": "boolean",
"description": "Nodes defines if metrics-server nodes api should get proxied from host to virtual cluster."
Expand All @@ -1737,7 +1752,8 @@
}
},
"additionalProperties": false,
"type": "object"
"type": "object",
"description": "MetricsServer reuses the metrics server from the host cluster within the vCluster."
},
"MutatingWebhook": {
"properties": {
Expand Down Expand Up @@ -1929,26 +1945,6 @@
"additionalProperties": false,
"type": "object"
},
"Observability": {
"properties": {
"metrics": {
"$ref": "#/$defs/ObservabilityMetrics",
"description": "Metrics allows to proxy metrics server apis from host to virtual cluster."
}
},
"additionalProperties": false,
"type": "object"
},
"ObservabilityMetrics": {
"properties": {
"proxy": {
"$ref": "#/$defs/MetricsProxy",
"description": "Proxy holds the configuration what metrics-server apis should get proxied."
}
},
"additionalProperties": false,
"type": "object"
},
"OutgoingConnections": {
"properties": {
"ipBlock": {
Expand Down Expand Up @@ -3042,6 +3038,10 @@
"$ref": "#/$defs/Sync",
"description": "Sync describes how to sync resources from the virtual cluster to host cluster and back."
},
"integrations": {
"$ref": "#/$defs/Integrations",
"description": "Integrations holds config for vCluster integrations with other operators or tools running on the host cluster"
},
"networking": {
"$ref": "#/$defs/Networking",
"description": "Networking options related to the virtual cluster."
Expand All @@ -3050,10 +3050,6 @@
"$ref": "#/$defs/Policies",
"description": "Policies to enforce for the virtual cluster deployment as well as within the virtual cluster."
},
"observability": {
"$ref": "#/$defs/Observability",
"description": "Observability holds options to proxy metrics from the host cluster into the virtual cluster."
},
"controlPlane": {
"$ref": "#/$defs/ControlPlane",
"description": "Configure vCluster's control plane components and deployment."
Expand Down
22 changes: 11 additions & 11 deletions chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,17 @@ sync:
all: false
labels: {}

# Integrations holds config for vCluster integrations with other operators or tools running on the host cluster
integrations:
# MetricsServer reuses the metrics server from the host cluster within the vCluster.
metricsServer:
# Enabled signals the metrics server integration should be enabled.
enabled: false
# Nodes defines if metrics-server nodes api should get proxied from host to virtual cluster.
nodes: true
# Pods defines if metrics-server pods api should get proxied from host to virtual cluster.
pods: true

# Configure vCluster's control plane components and deployment.
controlPlane:
# Distro holds virtual cluster related distro options. A distro cannot be changed after vCluster is deployed.
Expand Down Expand Up @@ -709,17 +720,6 @@ rbac:
# ExtraRules will add rules to the cluster role.
extraRules: []

# Observability holds options to proxy metrics from the host cluster into the virtual cluster.
observability:
# Metrics allows to proxy metrics server apis from host to virtual cluster.
metrics:
# Proxy holds the configuration what metrics-server apis should get proxied.
proxy:
# Nodes defines if metrics-server nodes api should get proxied from host to virtual cluster.
nodes: false
# Pods defines if metrics-server pods api should get proxied from host to virtual cluster.
pods: false

# Networking options related to the virtual cluster.
networking:
# ReplicateServices allows replicating services from the host within the virtual cluster or the other way around.
Expand Down
7 changes: 7 additions & 0 deletions cmd/vcluster/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"runtime/debug"

"github.com/loft-sh/vcluster/pkg/config"
"github.com/loft-sh/vcluster/pkg/integrations"
"github.com/loft-sh/vcluster/pkg/leaderelection"
"github.com/loft-sh/vcluster/pkg/plugin"
"github.com/loft-sh/vcluster/pkg/pro"
Expand Down Expand Up @@ -98,6 +99,12 @@ func ExecuteStart(ctx context.Context, options *StartOptions) error {
return fmt.Errorf("create controller context: %w", err)
}

// start integrations
err = integrations.StartIntegrations(controllerCtx)
if err != nil {
return fmt.Errorf("start integrations: %w", err)
}

// start proxy
err = setup.StartProxy(controllerCtx)
if err != nil {
Expand Down
42 changes: 21 additions & 21 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ type Config struct {
// Sync describes how to sync resources from the virtual cluster to host cluster and back.
Sync Sync `json:"sync,omitempty"`

// Integrations holds config for vCluster integrations with other operators or tools running on the host cluster
Integrations Integrations `json:"integrations,omitempty"`

// Networking options related to the virtual cluster.
Networking Networking `json:"networking,omitempty"`

// Policies to enforce for the virtual cluster deployment as well as within the virtual cluster.
Policies Policies `json:"policies,omitempty"`

// Observability holds options to proxy metrics from the host cluster into the virtual cluster.
Observability Observability `json:"observability,omitempty"`

// Configure vCluster's control plane components and deployment.
ControlPlane ControlPlane `json:"controlPlane,omitempty"`

Expand Down Expand Up @@ -76,6 +76,24 @@ type Config struct {
Plugin map[string]Plugin `json:"plugin,omitempty"`
}

// Integrations holds config for vCluster integrations with other operators or tools running on the host cluster
type Integrations struct {
// MetricsServer reuses the metrics server from the host cluster within the vCluster.
MetricsServer MetricsServer `json:"metricsServer,omitempty"`
}

// MetricsServer reuses the metrics server from the host cluster within the vCluster.
type MetricsServer struct {
// Enabled signals the metrics server integration should be enabled.
Enabled bool `json:"enabled,omitempty"`

// Nodes defines if metrics-server nodes api should get proxied from host to virtual cluster.
Nodes bool `json:"nodes,omitempty"`

// Pods defines if metrics-server pods api should get proxied from host to virtual cluster.
Pods bool `json:"pods,omitempty"`
}

// ExternalConfig holds external tool configuration
type ExternalConfig map[string]interface{}

Expand Down Expand Up @@ -415,11 +433,6 @@ type SyncNodeSelector struct {
Labels map[string]string `json:"labels,omitempty"`
}

type Observability struct {
// Metrics allows to proxy metrics server apis from host to virtual cluster.
Metrics ObservabilityMetrics `json:"metrics,omitempty"`
}

type ServiceMonitor struct {
// Enabled configures if Helm should create the service monitor.
Enabled bool `json:"enabled,omitempty"`
Expand All @@ -431,19 +444,6 @@ type ServiceMonitor struct {
Annotations map[string]string `json:"annotations,omitempty"`
}

type ObservabilityMetrics struct {
// Proxy holds the configuration what metrics-server apis should get proxied.
Proxy MetricsProxy `json:"proxy,omitempty"`
}

type MetricsProxy struct {
// Nodes defines if metrics-server nodes api should get proxied from host to virtual cluster.
Nodes bool `json:"nodes,omitempty"`

// Pods defines if metrics-server pods api should get proxied from host to virtual cluster.
Pods bool `json:"pods,omitempty"`
}

type Networking struct {
// ReplicateServices allows replicating services from the host within the virtual cluster or the other way around.
ReplicateServices ReplicateServices `json:"replicateServices,omitempty"`
Expand Down
11 changes: 7 additions & 4 deletions config/legacyconfig/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,12 @@ func convertBaseValues(oldConfig BaseHelm, newConfig *config.Config) error {
newConfig.Networking.ReplicateServices.ToHost = oldConfig.MapServices.FromVirtual

if oldConfig.Proxy.MetricsServer.Pods.Enabled != nil {
newConfig.Observability.Metrics.Proxy.Pods = *oldConfig.Proxy.MetricsServer.Pods.Enabled
newConfig.Integrations.MetricsServer.Enabled = true
newConfig.Integrations.MetricsServer.Pods = *oldConfig.Proxy.MetricsServer.Pods.Enabled
}
if oldConfig.Proxy.MetricsServer.Nodes.Enabled != nil {
newConfig.Observability.Metrics.Proxy.Nodes = *oldConfig.Proxy.MetricsServer.Nodes.Enabled
newConfig.Integrations.MetricsServer.Enabled = true
newConfig.Integrations.MetricsServer.Nodes = *oldConfig.Proxy.MetricsServer.Nodes.Enabled
}

if len(oldConfig.Volumes) > 0 {
Expand Down Expand Up @@ -1026,8 +1028,9 @@ func migrateFlag(key, value string, newConfig *config.Config) error {
}
case "proxy-metrics-server":
if value == "" || value == "true" {
newConfig.Observability.Metrics.Proxy.Pods = true
newConfig.Observability.Metrics.Proxy.Nodes = true
newConfig.Integrations.MetricsServer.Enabled = true
newConfig.Integrations.MetricsServer.Pods = true
newConfig.Integrations.MetricsServer.Nodes = true
}
case "service-account-token-secrets":
if value == "" || value == "true" {
Expand Down
12 changes: 6 additions & 6 deletions config/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ sync:
all: false
labels: {}

integrations:
metricsServer:
enabled: false
nodes: true
pods: true

controlPlane:
distro:
k8s:
Expand Down Expand Up @@ -423,12 +429,6 @@ rbac:
overwriteRules: []
extraRules: []

observability:
metrics:
proxy:
nodes: false
pods: false

networking:
replicateServices:
toHost: []
Expand Down
Loading

0 comments on commit 578a390

Please sign in to comment.