Skip to content

Commit 665265a

Browse files
authored
Merge pull request #17547 from hakman/no-crictl-nerdctl
containerd: Don't install crictl and nerdctl by default
2 parents a8001b8 + e8419e2 commit 665265a

File tree

367 files changed

+261
-931
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

367 files changed

+261
-931
lines changed

docs/releases/1.34-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This is a document to gather the release notes prior to the release.
77
# Significant changes
88

99
* Default SSH key is now `~/.ssh/id_ed25519.pub`, instead of the less secure `~/.ssh/id_rsa.pub`.
10+
* `crictl` and `nerdctl` are now only installed on demand, by setting `spec.containerd.installCriCtl=true` and `spec.containerd.installNerdCtl=true`.
1011

1112
## Some Feature
1213

k8s/crds/kops.k8s.io_clusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,12 @@ spec:
897897
description: ConfigOverride is the complete containerd config
898898
file provided by the user.
899899
type: string
900+
installCriCtl:
901+
description: InstallCriCtl installs crictl (default "false").
902+
type: boolean
903+
installNerdCtl:
904+
description: InstallNerdCtl installs nerdctl (default "false").
905+
type: boolean
900906
logLevel:
901907
description: LogLevel controls the logging details [trace, debug,
902908
info, warn, error, fatal, panic] (default "info").

k8s/crds/kops.k8s.io_instancegroups.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ spec:
133133
description: ConfigOverride is the complete containerd config
134134
file provided by the user.
135135
type: string
136+
installCriCtl:
137+
description: InstallCriCtl installs crictl (default "false").
138+
type: boolean
139+
installNerdCtl:
140+
description: InstallNerdCtl installs nerdctl (default "false").
141+
type: boolean
136142
logLevel:
137143
description: LogLevel controls the logging details [trace, debug,
138144
info, warn, error, fatal, panic] (default "info").

nodeup/pkg/model/crictl.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type CrictlBuilder struct {
3333
var _ fi.NodeupModelBuilder = &CrictlBuilder{}
3434

3535
func (b *CrictlBuilder) Build(c *fi.NodeupModelBuilderContext) error {
36+
if b.skipInstall() {
37+
klog.V(8).Info("won't install crictl")
38+
return nil
39+
}
40+
3641
assets := b.Assets.FindMatches(regexp.MustCompile(`^crictl$`))
3742
if len(assets) == 0 {
3843
klog.Warning("unable to find any crictl binaries in assets")
@@ -65,3 +70,13 @@ func (b *CrictlBuilder) binaryPath() string {
6570
}
6671
return path
6772
}
73+
74+
func (b *CrictlBuilder) skipInstall() bool {
75+
containerd := b.NodeupConfig.ContainerdConfig
76+
77+
if containerd == nil {
78+
return false
79+
}
80+
81+
return containerd.SkipInstall && !containerd.InstallCriCtl
82+
}

nodeup/pkg/model/nerdctl.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package model
1818

1919
import (
2020
"path/filepath"
21+
"regexp"
2122

2223
"k8s.io/klog/v2"
2324
"k8s.io/kops/upup/pkg/fi"
@@ -33,24 +34,28 @@ var _ fi.NodeupModelBuilder = &NerdctlBuilder{}
3334

3435
func (b *NerdctlBuilder) Build(c *fi.NodeupModelBuilderContext) error {
3536
if b.skipInstall() {
36-
klog.Info("containerd.skipInstall is set to true; won't install nerdctl")
37+
klog.V(8).Info("won't install nerdctl")
3738
return nil
3839
}
3940

40-
assetName := "nerdctl"
41-
assetPath := ""
42-
asset, err := b.Assets.Find(assetName, assetPath)
43-
if err != nil {
44-
klog.Warningf("unable to locate asset %q: %v", assetName, err)
41+
assets := b.Assets.FindMatches(regexp.MustCompile(`^nerdctl$`))
42+
if len(assets) == 0 {
43+
klog.Warning("unable to find any nerdctl binaries in assets")
44+
return nil
45+
}
46+
if len(assets) > 1 {
47+
klog.Warning("multiple nerdctl binaries are found")
4548
return nil
4649
}
4750

48-
c.AddTask(&nodetasks.File{
49-
Path: b.nerdctlPath(),
50-
Contents: asset,
51-
Type: nodetasks.FileType_File,
52-
Mode: s("0755"),
53-
})
51+
for k, v := range assets {
52+
c.AddTask(&nodetasks.File{
53+
Path: filepath.Join(b.binaryPath(), k),
54+
Contents: v,
55+
Type: nodetasks.FileType_File,
56+
Mode: s("0755"),
57+
})
58+
}
5459

5560
return nil
5661
}
@@ -64,19 +69,14 @@ func (b *NerdctlBuilder) binaryPath() string {
6469
path = "/home/kubernetes/bin"
6570
}
6671
return path
67-
68-
}
69-
70-
func (b *NerdctlBuilder) nerdctlPath() string {
71-
return filepath.Join(b.binaryPath(), "nerdctl")
7272
}
7373

7474
func (b *NerdctlBuilder) skipInstall() bool {
75-
d := b.NodeupConfig.ContainerdConfig
75+
containerd := b.NodeupConfig.ContainerdConfig
7676

77-
if d == nil {
77+
if containerd == nil {
7878
return false
7979
}
8080

81-
return d.SkipInstall
81+
return containerd.SkipInstall && !containerd.InstallNerdCtl
8282
}

pkg/apis/kops/containerdconfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ type ContainerdConfig struct {
6060
NRI *NRIConfig `json:"nri,omitempty"`
6161
// Enables Kubelet ECR Credential helper to pass credentials to containerd mirrors, to use ECR as a pull-through cache
6262
UseECRCredentialsForMirrors bool `json:"useECRCredentialsForMirrors,omitempty"`
63+
// InstallCriCtl installs crictl (default "false").
64+
InstallCriCtl bool `json:"installCriCtl,omitempty"`
65+
// InstallNerdCtl installs nerdctl (default "false").
66+
InstallNerdCtl bool `json:"installNerdCtl,omitempty"`
6367
}
6468

6569
type NRIConfig struct {

pkg/apis/kops/v1alpha2/containerdconfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type ContainerdConfig struct {
5353
NRI *NRIConfig `json:"nri,omitempty"`
5454
// Enables Kubelet ECR Credential helper to pass credentials to containerd mirrors, to use ECR as a pull-through cache
5555
UseECRCredentialsForMirrors bool `json:"useECRCredentialsForMirrors,omitempty"`
56+
// InstallCriCtl installs crictl (default "false").
57+
InstallCriCtl bool `json:"installCriCtl,omitempty"`
58+
// InstallNerdCtl installs nerdctl (default "false").
59+
InstallNerdCtl bool `json:"installNerdCtl,omitempty"`
5660
}
5761

5862
type NRIConfig struct {

pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/kops/v1alpha3/containerdconfig.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ type ContainerdConfig struct {
5353
NRI *NRIConfig `json:"nri,omitempty"`
5454
// Enables Kubelet ECR Credential helper to pass credentials to containerd mirrors, to use ECR as a pull-through cache
5555
UseECRCredentialsForMirrors bool `json:"useECRCredentialsForMirrors,omitempty"`
56+
// InstallCriCtl installs crictl (default "false").
57+
InstallCriCtl bool `json:"installCriCtl,omitempty"`
58+
// InstallNerdCtl installs nerdctl (default "false").
59+
InstallNerdCtl bool `json:"installNerdCtl,omitempty"`
5660
}
5761

5862
type NRIConfig struct {

pkg/apis/kops/v1alpha3/zz_generated.conversion.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)