Skip to content

Commit 0223537

Browse files
committed
Merge remote-tracking branch 'origin/main' into k0s-1-29
2 parents 8bc8e7f + d0cd9aa commit 0223537

File tree

16 files changed

+95
-38
lines changed

16 files changed

+95
-38
lines changed

cmd/buildtools/embeddedclusteroperator.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ var operatorImageComponents = map[string]addonComponent{
2121
"docker.io/library/busybox": {
2222
name: "utils",
2323
},
24+
"docker.io/bloomberg/goldpinger": {
25+
name: "goldpinger",
26+
useUpstreamImage: true,
27+
},
2428
}
2529

2630
var updateOperatorAddonCommand = &cli.Command{
@@ -130,9 +134,9 @@ func updateOperatorAddonImages(ctx context.Context, hcli helm.Client, chartURL s
130134
return fmt.Errorf("failed to get images from embedded cluster operator chart: %w", err)
131135
}
132136

133-
// make sure we include the operator util image as it does not show up when rendering the helm
134-
// chart.
137+
// make sure we include the operator util and goldpinger images as they don't show up when rendering the helm chart.
135138
images = append(images, "docker.io/library/busybox:latest")
139+
images = append(images, "docker.io/bloomberg/goldpinger:latest")
136140

137141
metaImages, err := UpdateImages(ctx, operatorImageComponents, embeddedclusteroperator.Metadata.Images, images)
138142
if err != nil {

cmd/installer/cli/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ func waitForNode(ctx context.Context) error {
976976
if err != nil {
977977
return fmt.Errorf("get hostname: %w", err)
978978
}
979-
if err := kubeutils.WaitForControllerNode(ctx, kcli, hostname); err != nil {
979+
if err := kubeutils.WaitForNode(ctx, kcli, hostname, false); err != nil {
980980
return fmt.Errorf("wait for node: %w", err)
981981
}
982982
return nil

cmd/installer/cli/join.go

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,26 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
182182
return err
183183
}
184184

185-
if isWorker {
186-
logrus.Debugf("worker node join finished")
187-
return nil
188-
}
189-
190185
kcli, err := kubeutils.KubeClient()
191186
if err != nil {
192187
return fmt.Errorf("unable to get kube client: %w", err)
193188
}
194189

190+
hostname, err := os.Hostname()
191+
if err != nil {
192+
return fmt.Errorf("unable to get hostname: %w", err)
193+
}
194+
195+
logrus.Debugf("waiting for node to join cluster")
196+
if err := waitForNodeToJoin(ctx, kcli, hostname, isWorker); err != nil {
197+
return fmt.Errorf("unable to wait for node: %w", err)
198+
}
199+
200+
if isWorker {
201+
logrus.Debugf("worker node join finished")
202+
return nil
203+
}
204+
195205
airgapChartsPath := ""
196206
if flags.isAirgap {
197207
airgapChartsPath = runtimeconfig.EmbeddedClusterChartsSubDir()
@@ -207,15 +217,6 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, jcmd *kotsadm
207217
}
208218
defer hcli.Close()
209219

210-
hostname, err := os.Hostname()
211-
if err != nil {
212-
return fmt.Errorf("unable to get hostname: %w", err)
213-
}
214-
215-
if err := waitForNodeToJoin(ctx, kcli, hostname); err != nil {
216-
return fmt.Errorf("unable to wait for node: %w", err)
217-
}
218-
219220
if flags.enableHighAvailability {
220221
if err := maybeEnableHA(ctx, kcli, hcli, flags.isAirgap, cidrCfg.ServiceCIDR, jcmd.InstallationSpec.Proxy, jcmd.InstallationSpec.Config); err != nil {
221222
return fmt.Errorf("unable to enable high availability: %w", err)
@@ -246,7 +247,12 @@ func runJoinVerifyAndPrompt(name string, flags JoinCmdFlags, jcmd *kotsadm.JoinC
246247
}
247248

248249
runtimeconfig.Set(jcmd.InstallationSpec.RuntimeConfig)
249-
os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeConfig())
250+
isWorker := !strings.Contains(jcmd.K0sJoinCommand, "controller")
251+
if isWorker {
252+
os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeletConfig())
253+
} else {
254+
os.Setenv("KUBECONFIG", runtimeconfig.PathToKubeConfig())
255+
}
250256
os.Setenv("TMPDIR", runtimeconfig.EmbeddedClusterTmpSubDir())
251257

252258
if err := runtimeconfig.WriteToDisk(); err != nil {
@@ -476,11 +482,11 @@ func runK0sInstallCommand(networkInterface string, fullcmd string) error {
476482
return nil
477483
}
478484

479-
func waitForNodeToJoin(ctx context.Context, kcli client.Client, hostname string) error {
485+
func waitForNodeToJoin(ctx context.Context, kcli client.Client, hostname string, isWorker bool) error {
480486
loading := spinner.Start()
481487
defer loading.Close()
482488
loading.Infof("Waiting for node to join the cluster")
483-
if err := kubeutils.WaitForControllerNode(ctx, kcli, hostname); err != nil {
489+
if err := kubeutils.WaitForNode(ctx, kcli, hostname, isWorker); err != nil {
484490
return fmt.Errorf("unable to wait for node: %w", err)
485491
}
486492
loading.Infof("Node has joined the cluster!")

e2e/scripts/enable-squid-whitelist.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function main() {
7676
maybe_install curl curl
7777

7878
# update the squid config to disable allow access from local networks
79-
sed -i 's/http_access allow localnet/# http_access allow localnet/' /etc/squid/conf.d/ec.conf
79+
sed -i 's/^http_access allow localnet$/http_access allow localnet whitelist/' /etc/squid/conf.d/ec.conf
8080

8181
# restart the squid service
8282
squid -k reconfigure

e2e/scripts/install-and-configure-squid.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ acl step1 at_step SslBump1
99
ssl_bump peek step1
1010
ssl_bump bump all
1111
12+
acl whitelist dstdomain \"/etc/squid/sites.whitelist.txt\"
13+
14+
# this will allow all access to the internet from local IPs
1215
http_access allow localnet
1316
14-
acl whitelist dstdomain \"/etc/squid/sites.whitelist.txt\"
15-
http_access allow whitelist
17+
# to restrict access so only local IPs can access the internet and only sites on the whitelist, instead use
18+
# http_access allow localnet whitelist
1619
"
1720

1821
whitelist_txt="

operator/charts/embedded-cluster-operator/templates/embedded-cluster-lam-service-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data:
2323
podSpec:
2424
containers:
2525
- image: {{ .Values.utilsImage }}
26-
imagePullPolicy: Always
26+
imagePullPolicy: IfNotPresent
2727
args: ["chroot","/host","cat","/etc/systemd/system/local-artifact-mirror.service.d/embedded-cluster.conf"]
2828
name: debugger
2929
resources: {}

operator/charts/embedded-cluster-operator/templates/embedded-cluster-logs-collector.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ data:
2323
podSpec:
2424
containers:
2525
- image: {{ .Values.utilsImage }}
26-
imagePullPolicy: Always
26+
imagePullPolicy: IfNotPresent
2727
args: ["chroot","/host","journalctl","-u","k0scontroller","--no-pager","--since","2 days ago"]
2828
name: debugger
2929
resources: {}
@@ -52,7 +52,7 @@ data:
5252
podSpec:
5353
containers:
5454
- image: {{ .Values.utilsImage }}
55-
imagePullPolicy: Always
55+
imagePullPolicy: IfNotPresent
5656
args: ["chroot","/host","journalctl","-u","k0sworker","--no-pager","--since","2 days ago"]
5757
name: debugger
5858
resources: {}
@@ -81,7 +81,7 @@ data:
8181
podSpec:
8282
containers:
8383
- image: {{ .Values.utilsImage }}
84-
imagePullPolicy: Always
84+
imagePullPolicy: IfNotPresent
8585
args: ["chroot","/host","journalctl","-u","local-artifact-mirror","--no-pager","--since","2 days ago"]
8686
name: debugger
8787
resources: {}

operator/charts/embedded-cluster-operator/templates/embedded-cluster-troubleshoot-goldpinger.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ data:
1919
collectors:
2020
- goldpinger:
2121
namespace: goldpinger
22-
image: proxy.replicated.com/anonymous/bloomberg/goldpinger@sha256:70416f19f1cbeedd344d37b08e64114779976b99905e0d018e71c437cde750dc
22+
image: {{ .Values.goldpingerImage }}
2323
podLaunchOptions:
24-
image: proxy.replicated.com/anonymous/library/busybox@sha256:768e5c6f5cb6db0794eec98dc7a967f40631746c32232b78a3105fb946f3ab83
24+
image: {{ .Values.utilsImage }}
2525
exclude: {{ .Values.isAirgap }}
2626
analyzers:
2727
- goldpinger:

operator/charts/embedded-cluster-operator/values.yaml.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ image:
1313
pullPolicy: IfNotPresent
1414

1515
utilsImage: busybox:latest
16+
goldpingerImage: bloomberg/goldpinger:latest
1617

1718
extraEnv: []
1819
# - name: HTTP_PROXY

pkg/addons/embeddedclusteroperator/static/metadata.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ images:
1313
tag:
1414
amd64: v1.19.0-k8s-1.30
1515
arm64: v1.19.0-k8s-1.30
16+
goldpinger:
17+
repo: proxy.replicated.com/anonymous/bloomberg/goldpinger
18+
tag:
19+
amd64: latest
20+
arm64: latest
1621
utils:
1722
repo: proxy.replicated.com/anonymous/replicated/ec-utils
1823
tag:

pkg/addons/embeddedclusteroperator/static/values.tpl.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ image:
77
repository: '{{ (index .Images "embedded-cluster-operator").Repo }}'
88
tag: '{{ index (index .Images "embedded-cluster-operator").Tag .GOARCH }}'
99
utilsImage: '{{ ImageString (index .Images "utils") }}'
10+
goldpingerImage: '{{ ImageString (index .Images "goldpinger") }}'
1011
{{- end }}

pkg/dryrun/kubeutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (k *KubeUtils) WaitForNodes(ctx context.Context, cli client.Client) error {
4444
return nil
4545
}
4646

47-
func (k *KubeUtils) WaitForControllerNode(ctx context.Context, kcli client.Client, name string) error {
47+
func (k *KubeUtils) WaitForNode(ctx context.Context, kcli client.Client, name string, isWorker bool) error {
4848
return nil
4949
}
5050

pkg/kubeutils/interface.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type KubeUtilsInterface interface {
2828
WaitForPodComplete(ctx context.Context, cli client.Client, ns, name string, opts *WaitOptions) error
2929
WaitForInstallation(ctx context.Context, cli client.Client, writer *spinner.MessageWriter) error
3030
WaitForNodes(ctx context.Context, cli client.Client) error
31-
WaitForControllerNode(ctx context.Context, kcli client.Client, name string) error
31+
WaitForNode(ctx context.Context, kcli client.Client, name string, isWorker bool) error
3232
IsNamespaceReady(ctx context.Context, cli client.Client, ns string) (bool, error)
3333
IsDeploymentReady(ctx context.Context, cli client.Client, ns, name string) (bool, error)
3434
IsStatefulSetReady(ctx context.Context, cli client.Client, ns, name string) (bool, error)
@@ -86,8 +86,8 @@ func WaitForNodes(ctx context.Context, cli client.Client) error {
8686
return kb.WaitForNodes(ctx, cli)
8787
}
8888

89-
func WaitForControllerNode(ctx context.Context, kcli client.Client, name string) error {
90-
return kb.WaitForControllerNode(ctx, kcli, name)
89+
func WaitForNode(ctx context.Context, kcli client.Client, name string, isWorker bool) error {
90+
return kb.WaitForNode(ctx, kcli, name, isWorker)
9191
}
9292

9393
func IsNamespaceReady(ctx context.Context, cli client.Client, ns string) (bool, error) {

pkg/kubeutils/kubeutils.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ func (k *KubeUtils) WaitForNodes(ctx context.Context, cli client.Client) error {
187187
return nil
188188
}
189189

190-
// WaitForControllerNode waits for a specific controller node to be registered with the cluster.
191-
func (k *KubeUtils) WaitForControllerNode(ctx context.Context, kcli client.Client, name string) error {
190+
// WaitForNode waits for a specific controller node to be registered with the cluster.
191+
func (k *KubeUtils) WaitForNode(ctx context.Context, kcli client.Client, name string, isWorker bool) error {
192192
backoff := wait.Backoff{Steps: 60, Duration: 5 * time.Second, Factor: 1.0, Jitter: 0.1}
193193
var lasterr error
194194
if err := wait.ExponentialBackoffWithContext(
@@ -198,9 +198,11 @@ func (k *KubeUtils) WaitForControllerNode(ctx context.Context, kcli client.Clien
198198
lasterr = fmt.Errorf("unable to get node: %v", err)
199199
return false, nil
200200
}
201-
if _, ok := node.Labels["node-role.kubernetes.io/control-plane"]; !ok {
202-
lasterr = fmt.Errorf("control plane label not found")
203-
return false, nil
201+
if !isWorker {
202+
if _, ok := node.Labels["node-role.kubernetes.io/control-plane"]; !ok {
203+
lasterr = fmt.Errorf("control plane label not found")
204+
return false, nil
205+
}
204206
}
205207
for _, condition := range node.Status.Conditions {
206208
if condition.Type == corev1.NodeReady && condition.Status == corev1.ConditionTrue {

pkg/runtimeconfig/runtimeconfig.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ func PathToKubeConfig() string {
121121
return filepath.Join(EmbeddedClusterK0sSubDir(), "pki/admin.conf")
122122
}
123123

124+
// PathToKubeletConfig returns the path to the kubelet config file.
125+
func PathToKubeletConfig() string {
126+
return filepath.Join(EmbeddedClusterK0sSubDir(), "kubelet.conf")
127+
}
128+
124129
// EmbeddedClusterSupportSubDir returns the path to the directory where embedded-cluster
125130
// support files are stored. Things that are useful when providing end user support in
126131
// a running cluster should be stored into this directory.

tests/dryrun/join_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,33 @@ func TestJoinRunPreflights(t *testing.T) {
176176
dryrunJoin(t, "run-preflights", "10.0.0.1", "some-token")
177177
t.Logf("%s: test complete", time.Now().Format(time.RFC3339))
178178
}
179+
180+
func TestJoinWorkerNode(t *testing.T) {
181+
drFile := filepath.Join(t.TempDir(), "ec-dryrun.yaml")
182+
client := &dryrun.Client{
183+
Kotsadm: dryrun.NewKotsadm(),
184+
}
185+
clusterID := uuid.New()
186+
jcmd := &kotsadm.JoinCommandResponse{
187+
K0sJoinCommand: "/usr/local/bin/k0s install worker --no-taints --labels kots.io/embedded-cluster-role=total-1,kots.io/embedded-cluster-role-0=worker-test,worker-label=worker-label-value",
188+
K0sToken: "some-k0s-token",
189+
EmbeddedClusterVersion: "v0.0.0",
190+
ClusterID: clusterID,
191+
InstallationSpec: ecv1beta1.InstallationSpec{
192+
ClusterID: clusterID.String(),
193+
Config: &ecv1beta1.ConfigSpec{
194+
UnsupportedOverrides: ecv1beta1.UnsupportedOverrides{},
195+
},
196+
},
197+
}
198+
client.Kotsadm.SetGetJoinTokenResponse("10.0.0.1", "some-token", jcmd, nil)
199+
dryrun.Init(drFile, client)
200+
dr := dryrunJoin(t, "10.0.0.1", "some-token")
201+
202+
// --- validate os env --- //
203+
assertEnv(t, dr.OSEnv, map[string]string{
204+
"KUBECONFIG": "/var/lib/embedded-cluster/k0s/kubelet.conf", // uses kubelet config
205+
})
206+
207+
t.Logf("%s: test complete", time.Now().Format(time.RFC3339))
208+
}

0 commit comments

Comments
 (0)