Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[v0.21] Merge pull request #2297 from neogopher/fix-set-etcd-headless-endpoints-correctly #2299

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions chart/templates/etcd-headless-service.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{{- if not .Values.experimental.isolatedControlPlane.headless }}
{{- if or .Values.controlPlane.backingStore.etcd.deploy.enabled (include "vcluster.etcd.embedded.migrate" .) }}
{{- if .Values.controlPlane.backingStore.etcd.deploy.headlessService.enabled }}
apiVersion: v1
kind: Service
metadata:
Expand Down Expand Up @@ -33,4 +32,3 @@ spec:
release: "{{ .Release.Name }}"
{{- end }}
{{- end }}
{{- end }}
4 changes: 0 additions & 4 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,6 @@
},
"EtcdDeployHeadlessService": {
"properties": {
"enabled": {
"type": "boolean",
"description": "Enabled defines if the etcd headless service should be deployed"
},
"annotations": {
"additionalProperties": {
"type": "string"
Expand Down
1 change: 0 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ controlPlane:
annotations: {}
# HeadlessService holds options for the external etcd headless service.
headlessService:
enabled: true
annotations: {}

# Proxy defines options for the virtual cluster control plane proxy that is used to do authentication and intercept requests.
Expand Down
3 changes: 0 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,9 +1175,6 @@ type EtcdDeployService struct {
}

type EtcdDeployHeadlessService struct {
// Enabled defines if the etcd headless service should be deployed
Enabled bool `json:"enabled,omitempty"`

// Annotations are extra annotations for the external etcd headless service
Annotations map[string]string `json:"annotations,omitempty"`
}
Expand Down
1 change: 0 additions & 1 deletion config/legacyconfig/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ func convertEtcd(oldConfig EtcdValues, newConfig *config.Config) error {
if oldConfig.Disabled {
newConfig.ControlPlane.BackingStore.Etcd.Deploy.StatefulSet.Enabled = false
newConfig.ControlPlane.BackingStore.Etcd.Deploy.Service.Enabled = false
newConfig.ControlPlane.BackingStore.Etcd.Deploy.HeadlessService.Enabled = false
}
if oldConfig.ImagePullPolicy != "" {
newConfig.ControlPlane.BackingStore.Etcd.Deploy.StatefulSet.ImagePullPolicy = oldConfig.ImagePullPolicy
Expand Down
1 change: 0 additions & 1 deletion config/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ controlPlane:
enabled: true
annotations: {}
headlessService:
enabled: true
annotations: {}

proxy:
Expand Down
4 changes: 3 additions & 1 deletion pkg/etcd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func NewFromConfig(ctx context.Context, vConfig *config.VirtualClusterConfig) (C

if vConfig.ControlPlane.BackingStore.Etcd.Embedded.Enabled {
etcdEndpoints = "https://127.0.0.1:2379"
} else {
} else if vConfig.ControlPlane.BackingStore.Etcd.Deploy.Service.Enabled {
etcdEndpoints = "https://" + vConfig.Name + "-etcd:2379"
} else {
etcdEndpoints = "https://" + vConfig.Name + "-etcd-headless:2379"
}
} else if vConfig.Distro() == vconfig.K8SDistro {
etcdEndpoints = constants.K8sKineEndpoint
Expand Down
13 changes: 12 additions & 1 deletion pkg/k0s/k0s.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ spec:
storage:
etcd:
externalCluster:
{{- if .Values.controlPlane.backingStore.etcd.deploy.service.enabled }}
endpoints: ["{{ .Release.Name }}-etcd:2379"]
{{- else }}
endpoints: ["{{ .Release.Name }}-etcd-headless:2379"]
{{- end }}
caFile: /data/k0s/pki/etcd/ca.crt
etcdPrefix: "/registry"
clientCertFile: /data/k0s/pki/apiserver-etcd-client.crt
Expand Down Expand Up @@ -96,11 +100,18 @@ func StartK0S(ctx context.Context, cancel context.CancelFunc, vConfig *config.Vi

// wait until etcd is up and running
if vConfig.ControlPlane.BackingStore.Etcd.Deploy.Enabled {
var etcdEndpoint string
if vConfig.ControlPlane.BackingStore.Etcd.Deploy.Service.Enabled {
etcdEndpoint = "https://" + vConfig.Name + "-etcd:2379"
} else {
etcdEndpoint = "https://" + vConfig.Name + "-etcd-headless:2379"
}

err := etcd.WaitForEtcd(ctx, &etcd.Certificates{
CaCert: "/data/k0s/pki/etcd/ca.crt",
ServerCert: "/data/k0s/pki/apiserver-etcd-client.crt",
ServerKey: "/data/k0s/pki/apiserver-etcd-client.key",
}, "https://"+vConfig.Name+"-etcd:2379")
}, etcdEndpoint)
if err != nil {
return err
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/k3s/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,24 @@ func StartK3S(ctx context.Context, vConfig *config.VirtualClusterConfig, service
args = append(args, "--kube-apiserver-arg=endpoint-reconciler-type=none")
}
if vConfig.ControlPlane.BackingStore.Etcd.Deploy.Enabled {
var etcdEndpoint string
if vConfig.ControlPlane.BackingStore.Etcd.Deploy.Service.Enabled {
etcdEndpoint = "https://" + vConfig.Name + "-etcd:2379"
} else {
etcdEndpoint = "https://" + vConfig.Name + "-etcd-headless:2379"
}

// wait until etcd is up and running
err := etcd.WaitForEtcd(ctx, &etcd.Certificates{
CaCert: "/data/pki/etcd/ca.crt",
ServerCert: "/data/pki/apiserver-etcd-client.crt",
ServerKey: "/data/pki/apiserver-etcd-client.key",
}, "https://"+vConfig.Name+"-etcd:2379")
}, etcdEndpoint)
if err != nil {
return err
}

args = append(args, "--datastore-endpoint=https://"+vConfig.Name+"-etcd:2379")
args = append(args, "--datastore-endpoint="+etcdEndpoint)
args = append(args, "--datastore-cafile=/data/pki/etcd/ca.crt")
args = append(args, "--datastore-certfile=/data/pki/apiserver-etcd-client.crt")
args = append(args, "--datastore-keyfile=/data/pki/apiserver-etcd-client.key")
Expand Down
4 changes: 3 additions & 1 deletion pkg/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ func StartK8S(

if vConfig.ControlPlane.BackingStore.Etcd.Embedded.Enabled {
etcdEndpoints = "https://127.0.0.1:2379"
} else {
} else if vConfig.ControlPlane.BackingStore.Etcd.Deploy.Service.Enabled {
etcdEndpoints = "https://" + vConfig.Name + "-etcd:2379"
} else {
etcdEndpoints = "https://" + vConfig.Name + "-etcd-headless:2379"
}
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/setup/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ func initialize(ctx context.Context, parentCtx context.Context, options *config.
// migrate from
migrateFrom := ""
if options.ControlPlane.BackingStore.Etcd.Embedded.Enabled && options.ControlPlane.BackingStore.Etcd.Embedded.MigrateFromDeployedEtcd {
migrateFrom = "https://" + options.Name + "-etcd:2379"
if options.ControlPlane.BackingStore.Etcd.Deploy.Service.Enabled {
migrateFrom = "https://" + options.Name + "-etcd:2379"
} else {
migrateFrom = "https://" + options.Name + "-etcd-headless:2379"
}
}

// retrieve service cidr
Expand Down Expand Up @@ -228,6 +232,7 @@ func GenerateCerts(ctx context.Context, currentNamespaceClient kubernetes.Interf
etcdSans := []string{
"localhost",
etcdService,
etcdService + "-headless",
etcdService + "." + currentNamespace,
etcdService + "." + currentNamespace + ".svc",
}
Expand Down
Loading