From bd9cf4a3dc6602b30b3302ba6c0492ca406c01a0 Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Mon, 26 Feb 2024 00:05:31 +0900 Subject: [PATCH] Fix nits error messages --- nodeup/pkg/model/crictl.go | 21 +++++++++++++++++++-- nodeup/pkg/model/nerdctl.go | 23 ++++++++++++++++++++--- upup/pkg/fi/cloudup/crictl.go | 16 ++++++++++++++++ upup/pkg/fi/cloudup/crictl_test.go | 16 ++++++++++++++++ upup/pkg/fi/cloudup/nerdctl.go | 20 ++++++++++++++++---- 5 files changed, 87 insertions(+), 9 deletions(-) diff --git a/nodeup/pkg/model/crictl.go b/nodeup/pkg/model/crictl.go index 1221698625..6fb7782f84 100644 --- a/nodeup/pkg/model/crictl.go +++ b/nodeup/pkg/model/crictl.go @@ -1,7 +1,24 @@ +/* +Copyright 2024 The Kubernetes 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 model import ( "fmt" + "path/filepath" "k8s.io/kops/upup/pkg/fi" "k8s.io/kops/upup/pkg/fi/nodeup/nodetasks" @@ -19,7 +36,7 @@ func (b *CrictlBuilder) Build(c *fi.NodeupModelBuilderContext) error { assetPath := "" asset, err := b.Assets.Find(assetName, assetPath) if err != nil { - return fmt.Errorf("unable to locate asset %q", err) + return fmt.Errorf("unable to locate asset %q: %w", assetName, err) } c.AddTask(&nodetasks.File{ @@ -44,5 +61,5 @@ func (b *CrictlBuilder) binaryPath() string { } func (b *CrictlBuilder) crictlPath() string { - return b.binaryPath() + "/crictl" + return filepath.Join(b.binaryPath(), "crictl") } diff --git a/nodeup/pkg/model/nerdctl.go b/nodeup/pkg/model/nerdctl.go index d78c42918f..ac9e674b9d 100644 --- a/nodeup/pkg/model/nerdctl.go +++ b/nodeup/pkg/model/nerdctl.go @@ -1,7 +1,24 @@ +/* +Copyright 2024 The Kubernetes 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 model import ( "fmt" + "path/filepath" "k8s.io/klog/v2" "k8s.io/kops/upup/pkg/fi" @@ -17,7 +34,7 @@ var _ fi.NodeupModelBuilder = &NerdctlBuilder{} func (b *NerdctlBuilder) Build(c *fi.NodeupModelBuilderContext) error { if b.skipInstall() { - klog.Info("SkipInstall is set to true; won't install nerdctl") + klog.Info("containerd.skipInstall is set to true; won't install nerdctl") return nil } @@ -25,7 +42,7 @@ func (b *NerdctlBuilder) Build(c *fi.NodeupModelBuilderContext) error { assetPath := "" asset, err := b.Assets.Find(assetName, assetPath) if err != nil { - return fmt.Errorf("unable to locate asset %q", assetName) + return fmt.Errorf("unable to locate asset %q: %w", assetName, err) } c.AddTask(&nodetasks.File{ @@ -51,7 +68,7 @@ func (b *NerdctlBuilder) binaryPath() string { } func (b *NerdctlBuilder) nerdctlPath() string { - return b.binaryPath() + "/nerdctl" + return filepath.Join(b.binaryPath(), "nerdctl") } func (b *NerdctlBuilder) skipInstall() bool { diff --git a/upup/pkg/fi/cloudup/crictl.go b/upup/pkg/fi/cloudup/crictl.go index 09011bbdd9..444a63e3ba 100644 --- a/upup/pkg/fi/cloudup/crictl.go +++ b/upup/pkg/fi/cloudup/crictl.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes 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 cloudup import ( diff --git a/upup/pkg/fi/cloudup/crictl_test.go b/upup/pkg/fi/cloudup/crictl_test.go index 718aafcc42..639dacf84c 100644 --- a/upup/pkg/fi/cloudup/crictl_test.go +++ b/upup/pkg/fi/cloudup/crictl_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes 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 cloudup import ( diff --git a/upup/pkg/fi/cloudup/nerdctl.go b/upup/pkg/fi/cloudup/nerdctl.go index 207e5f71fe..69824e49fe 100644 --- a/upup/pkg/fi/cloudup/nerdctl.go +++ b/upup/pkg/fi/cloudup/nerdctl.go @@ -1,3 +1,19 @@ +/* +Copyright 2024 The Kubernetes 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 cloudup import ( @@ -18,10 +34,6 @@ const ( ) func findNerdctlAsset(c *kops.Cluster, assetBuilder *assets.AssetBuilder, arch architectures.Architecture) (*url.URL, *hashing.Hash, error) { - if c.Spec.Containerd == nil { - return nil, nil, fmt.Errorf("unable to find containerd config") - } - var assetURL, assetHash string switch arch { case architectures.ArchitectureAmd64: