mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-31 03:21:15 +02:00
This changes the data partition name to something more appropriate. We chose ephemeral to make it very clear that the disk should not be used for application data. Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
193 lines
4.9 KiB
Go
193 lines
4.9 KiB
Go
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package userdata
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/suite"
|
|
yaml "gopkg.in/yaml.v2"
|
|
)
|
|
|
|
type validateSuite struct {
|
|
suite.Suite
|
|
}
|
|
|
|
func TestValidateSuite(t *testing.T) {
|
|
suite.Run(t, new(validateSuite))
|
|
}
|
|
|
|
func (suite *validateSuite) TestDownloadRetry() {
|
|
// Disable logging for test
|
|
log.SetOutput(ioutil.Discard)
|
|
ts := testUDServer()
|
|
defer ts.Close()
|
|
|
|
var err error
|
|
|
|
_, err = Download(ts.URL, WithMaxWait(0.1))
|
|
suite.Require().NoError(err)
|
|
|
|
_, err = Download(ts.URL, WithFormat(b64), WithRetries(1), WithHeaders(map[string]string{"Metadata": "true", "format": b64}))
|
|
suite.Require().NoError(err)
|
|
log.SetOutput(os.Stderr)
|
|
}
|
|
|
|
func (suite *validateSuite) TestKubeadmMarshal() {
|
|
var kubeadm Kubeadm
|
|
|
|
err := yaml.Unmarshal([]byte(kubeadmConfig), &kubeadm)
|
|
suite.Require().NoError(err)
|
|
|
|
assert.Equal(suite.T(), "test", kubeadm.CertificateKey)
|
|
|
|
out, err := yaml.Marshal(&kubeadm)
|
|
suite.Require().NoError(err)
|
|
|
|
assert.Equal(suite.T(), kubeadmConfig, string(out))
|
|
}
|
|
|
|
func testUDServer() *httptest.Server {
|
|
var count int
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
count++
|
|
log.Printf("Request %d\n", count)
|
|
if count < 2 {
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
}
|
|
|
|
if r.Header.Get("format") == b64 {
|
|
// nolint: errcheck
|
|
w.Write([]byte(base64.StdEncoding.EncodeToString([]byte(testConfig))))
|
|
} else {
|
|
// nolint: errcheck
|
|
w.Write([]byte(testConfig))
|
|
}
|
|
}))
|
|
|
|
return ts
|
|
}
|
|
|
|
// nolint: lll
|
|
const testConfig = `version: "1"
|
|
security:
|
|
os:
|
|
ca:
|
|
crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
|
|
key: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0=
|
|
identity:
|
|
crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
|
|
key: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0=
|
|
kubernetes:
|
|
ca:
|
|
crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
|
|
key: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0=
|
|
sa:
|
|
crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
|
|
key: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0=
|
|
frontproxy:
|
|
crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
|
|
key: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0=
|
|
etcd:
|
|
crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0=
|
|
key: LS0tLS1CRUdJTiBFQyBQUklWQVRFIEtFWS0tLS0tCi0tLS0tRU5EIEVDIFBSSVZBVEUgS0VZLS0tLS0=
|
|
networking:
|
|
os: {}
|
|
kubernetes: {}
|
|
services:
|
|
init:
|
|
cni: flannel
|
|
kubeadm:
|
|
initToken: 528d1ad6-3485-49ad-94cd-0f44a35877ac
|
|
certificateKey: 'test'
|
|
configuration: |
|
|
apiVersion: kubeadm.k8s.io/v1beta1
|
|
kind: InitConfiguration
|
|
localAPIEndpoint:
|
|
bindPort: 6443
|
|
bootstrapTokens:
|
|
- token: '1qbsj9.3oz5hsk6grdfp98b'
|
|
ttl: 0s
|
|
---
|
|
apiVersion: kubeadm.k8s.io/v1beta1
|
|
kind: ClusterConfiguration
|
|
clusterName: test
|
|
kubernetesVersion: v1.16.0-alpha.3
|
|
---
|
|
apiVersion: kubeproxy.config.k8s.io/v1alpha1
|
|
kind: KubeProxyConfiguration
|
|
mode: ipvs
|
|
ipvs:
|
|
scheduler: lc
|
|
trustd:
|
|
username: 'test'
|
|
password: 'test'
|
|
endpoints: [ "1.2.3.4" ]
|
|
certSANs: []
|
|
install:
|
|
wipe: true
|
|
force: true
|
|
boot:
|
|
force: true
|
|
device: /dev/sda
|
|
size: 1024000000
|
|
ephemeral:
|
|
force: true
|
|
device: /dev/sda
|
|
size: 1024000000
|
|
`
|
|
|
|
// nolint: lll
|
|
const kubeadmConfig = `configuration: |
|
|
apiVersion: kubeadm.k8s.io/v1beta2
|
|
bootstrapTokens:
|
|
- groups:
|
|
- system:bootstrappers:kubeadm:default-node-token
|
|
token: 1qbsj9.3oz5hsk6grdfp98b
|
|
ttl: 0s
|
|
usages:
|
|
- signing
|
|
- authentication
|
|
kind: InitConfiguration
|
|
localAPIEndpoint:
|
|
advertiseAddress: 192.168.88.11
|
|
bindPort: 6443
|
|
nodeRegistration:
|
|
criSocket: /var/run/dockershim.sock
|
|
name: smiradell
|
|
taints:
|
|
- effect: NoSchedule
|
|
key: node-role.kubernetes.io/master
|
|
---
|
|
apiServer:
|
|
timeoutForControlPlane: 4m0s
|
|
apiVersion: kubeadm.k8s.io/v1beta2
|
|
certificatesDir: /etc/kubernetes/pki
|
|
clusterName: test
|
|
controllerManager: {}
|
|
dns:
|
|
type: CoreDNS
|
|
etcd:
|
|
local:
|
|
dataDir: /var/lib/etcd
|
|
imageRepository: k8s.gcr.io
|
|
kind: ClusterConfiguration
|
|
kubernetesVersion: v1.16.0-alpha.3
|
|
networking:
|
|
dnsDomain: cluster.local
|
|
serviceSubnet: 10.96.0.0/12
|
|
scheduler: {}
|
|
certificateKey: test
|
|
initToken: 528d1ad6-3485-49ad-94cd-0f44a35877ac
|
|
`
|