-
Notifications
You must be signed in to change notification settings - Fork 482
Add support for external etcd cluster #1165
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
Merged
ncopa
merged 17 commits into
k0sproject:main
from
jewertow:feat/external-etcd-cluster-support
Jan 3, 2022
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3dfbb69
Extend ClusterConfig CRD with etcd.externalCluster
jewertow b767e4e
Pass to kube-apiserver defined etcd-prefix and external endpoints
jewertow 6ca36bd
Validate etcd configuration
jewertow 40eb9ea
Configure etcd client to use external cluster if configured
jewertow a0546fe
Skip running internal etcd when external cluster is configured
jewertow b327abd
Extend CRD 'spec.storage.etcd.externalCluster' with TLS config options
jewertow 82fb30b
Validate TLS configs of external etcd cluster
jewertow b80067b
Support TLS when external etcd is used
jewertow a7c7b41
Add unit tests for exported methods of EtcdConfig
jewertow a3f88a7
Add unit tests for controller.APIServer
jewertow 8deab18
Disable commands 'k0s etcd' and 'k0s backup' when external etcd is used
jewertow 9c06e0a
Rewrite tests in storage_test.go to table-driven tests
jewertow 60515a0
Add smoke test for k0s with external etcd
jewertow 9c6112b
Use alpine image to run external etcd
jewertow 8e3232e
Fix etcd_arch
jewertow 1fe9da5
Refactor FootlooseSuite
jewertow 39afd19
Add tests for 'k0s etcd' command
jewertow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /* | ||
| Copyright 2021 k0s 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 externaletcd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "github.com/avast/retry-go" | ||
| "github.com/k0sproject/k0s/inttest/common" | ||
| "github.com/stretchr/testify/suite" | ||
| v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "testing" | ||
| ) | ||
|
|
||
| const k0sConfig = ` | ||
| spec: | ||
| storage: | ||
| type: etcd | ||
| etcd: | ||
| externalCluster: | ||
| endpoints: | ||
| - http://etcd0:2379 | ||
| etcdPrefix: k0s-tenant | ||
| ` | ||
|
|
||
| type ExternalEtcdSuite struct { | ||
| common.FootlooseSuite | ||
| } | ||
|
|
||
| func (s *ExternalEtcdSuite) TestK0sWithExternalEtcdCluster() { | ||
| s.T().Log("starting etcd") | ||
| err := retry.Do(func() error { | ||
| ssh, err := s.SSH(s.ExternalEtcd(0)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer ssh.Disconnect() | ||
|
|
||
| _, err = ssh.ExecWithOutput( | ||
| "ETCD_ADVERTISE_CLIENT_URLS=\"http://etcd0:2379\" " + | ||
| "ETCD_LISTEN_CLIENT_URLS=\"http://0.0.0.0:2379\" " + | ||
| "/opt/etcd > /var/log/etcd.log 2>&1 &") | ||
| return err | ||
| }) | ||
| s.Require().NoError(err) | ||
|
|
||
| s.T().Log("configuring k0s controller to resolve etcd0 hostname") | ||
| k0sControllerSSH, err := s.SSH(s.ControllerNode(0)) | ||
| s.Require().NoError(err) | ||
| defer k0sControllerSSH.Disconnect() | ||
|
|
||
| _, err = k0sControllerSSH.ExecWithOutput(fmt.Sprintf("echo '%s etcd0' >> /etc/hosts", s.GetExternalEtcdIPAddress())) | ||
| s.Require().NoError(err) | ||
|
|
||
| s.T().Log("starting k0s controller and worker") | ||
| s.PutFile(s.ControllerNode(0), "/tmp/k0s.yaml", k0sConfig) | ||
| s.Require().NoError(s.InitController(0, "--config=/tmp/k0s.yaml")) | ||
| s.Require().NoError(s.RunWorkers()) | ||
|
|
||
| kc, err := s.KubeClient(s.ControllerNode(0)) | ||
| s.NoError(err) | ||
|
|
||
| err = s.WaitForNodeReady(s.WorkerNode(0), kc) | ||
| s.NoError(err) | ||
|
|
||
| pods, err := kc.CoreV1().Pods("kube-system").List(context.TODO(), v1.ListOptions{ | ||
| Limit: 100, | ||
| }) | ||
| s.NoError(err) | ||
|
|
||
| podCount := len(pods.Items) | ||
| s.T().Logf("found %d pods in kube-system", podCount) | ||
| s.Greater(podCount, 0, "expecting to see few pods in kube-system namespace") | ||
|
|
||
| s.T().Log("checking if etcd contains keys") | ||
| etcdSSH, err := s.SSH(s.ExternalEtcd(0)) | ||
| s.Require().NoError(err) | ||
| defer etcdSSH.Disconnect() | ||
|
|
||
| output, err := etcdSSH.ExecWithOutput( | ||
| "ETCDCTL_API=3 /opt/etcdctl --endpoints=http://127.0.0.1:2379 get /k0s-tenant/services/specs/kube-system/kube-dns --keys-only") | ||
| s.Require().NoError(err) | ||
| s.Require().Contains(output, "/k0s-tenant/services/specs/kube-system/kube-dns") | ||
|
|
||
| etcdLeaveOutput, err := k0sControllerSSH.ExecWithOutput("k0s etcd leave --config=/tmp/k0s.yaml") | ||
| s.Require().Error(err) | ||
| s.Require().Contains(etcdLeaveOutput, "command 'k0s etcd' does not support external etcd cluster") | ||
|
|
||
| etcdListOutput, err := k0sControllerSSH.ExecWithOutput("k0s etcd member-list --config=/tmp/k0s.yaml") | ||
| s.Require().Error(err) | ||
| s.Require().Contains(etcdListOutput, "command 'k0s etcd' does not support external etcd cluster") | ||
|
|
||
| backupOutput, err := k0sControllerSSH.ExecWithOutput("k0s backup --config=/tmp/k0s.yaml") | ||
| s.Require().Error(err) | ||
| s.Require().Contains(backupOutput, "command 'k0s backup' does not support external etcd cluster") | ||
| } | ||
|
|
||
| func TestExternalEtcdSuite(t *testing.T) { | ||
| s := ExternalEtcdSuite{ | ||
| common.FootlooseSuite{ | ||
| ControllerCount: 1, | ||
| WorkerCount: 1, | ||
| WithExternalEtcd: true, | ||
| }, | ||
| } | ||
| suite.Run(t, &s) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.