Skip to content

Commit

Permalink
Merge pull request #2300 from neogopher/backport/v0.20/pr-2297
Browse files Browse the repository at this point in the history
[v0.20] Merge pull request #2297 from neogopher/fix-set-etcd-headless-endpoints-correctly
  • Loading branch information
FabianKramm authored Nov 28, 2024
2 parents 8e9bdbc + a75c712 commit 24bb497
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 17 deletions.
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 @@ -1022,10 +1022,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 @@ -390,7 +390,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 @@ -958,9 +958,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 @@ -140,7 +140,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 @@ -214,7 +214,6 @@ controlPlane:
enabled: true
annotations: {}
headlessService:
enabled: true
annotations: {}

proxy:
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.WaitForEtcdClient(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 @@ -50,17 +50,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.WaitForEtcdClient(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 @@ -231,6 +235,7 @@ func GenerateCerts(ctx context.Context, currentNamespaceClient kubernetes.Interf
etcdSans := []string{
"localhost",
etcdService,
etcdService + "-headless",
etcdService + "." + currentNamespace,
etcdService + "." + currentNamespace + ".svc",
}
Expand Down

0 comments on commit 24bb497

Please sign in to comment.