From 1c33f9ed8945914642ee77b745ad654540fb7b9d Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Wed, 2 Oct 2024 11:32:08 +0200 Subject: [PATCH] Remove the now unused manifestsSaver Its functionality has been inlined into the components. Signed-off-by: Tom Wieczorek --- pkg/component/controller/calico.go | 4 -- pkg/component/controller/calico_test.go | 7 --- pkg/component/controller/manifests.go | 59 ------------------------- 3 files changed, 70 deletions(-) delete mode 100644 pkg/component/controller/manifests.go diff --git a/pkg/component/controller/calico.go b/pkg/component/controller/calico.go index cf24088da17f..b07899abf24d 100644 --- a/pkg/component/controller/calico.go +++ b/pkg/component/controller/calico.go @@ -63,10 +63,6 @@ const ( calicoModeVXLAN calicoMode = "vxlan" ) -type manifestsSaver interface { - Save(dst string, content []byte) error -} - type calicoConfig struct { MTU int Mode calicoMode diff --git a/pkg/component/controller/calico_test.go b/pkg/component/controller/calico_test.go index c862f1ad647e..2a09331dbb84 100644 --- a/pkg/component/controller/calico_test.go +++ b/pkg/component/controller/calico_test.go @@ -30,13 +30,6 @@ import ( "sigs.k8s.io/yaml" ) -type inMemorySaver map[string][]byte - -func (i inMemorySaver) Save(dst string, content []byte) error { - i[dst] = content - return nil -} - func TestCalicoManifests(t *testing.T) { newTestInstance := func(t *testing.T) *Calico { k0sVars, err := config.NewCfgVars(nil, t.TempDir()) diff --git a/pkg/component/controller/manifests.go b/pkg/component/controller/manifests.go deleted file mode 100644 index 25df418d6850..000000000000 --- a/pkg/component/controller/manifests.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright 2020 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 controller - -import ( - "crypto/md5" - "fmt" - "path/filepath" - - "github.com/k0sproject/k0s/internal/pkg/dir" - "github.com/k0sproject/k0s/internal/pkg/file" - "github.com/k0sproject/k0s/pkg/constant" - "github.com/sirupsen/logrus" -) - -// FsManifestsSaver saves all given manifests under the specified root dir -type FsManifestsSaver struct { - dir string -} - -// Save saves given manifest under the given path -func (f FsManifestsSaver) Save(dst string, content []byte) error { - target := filepath.Join(f.dir, dst) - - if err := file.WriteContentAtomically(target, content, constant.CertMode); err != nil { - return err - } - - logrus.WithField("component", "manifest-saver").Debugf("Successfully wrote %s:%s", target, hash(content)) - return nil -} - -func hash(data []byte) string { - return fmt.Sprintf("%x", md5.Sum(data)) -} - -// NewManifestsSaver builds new filesystem manifests saver -func NewManifestsSaver(manifest string, dataDir string) (*FsManifestsSaver, error) { - manifestDir := filepath.Join(dataDir, "manifests", manifest) - err := dir.Init(manifestDir, constant.ManifestsDirMode) - if err != nil { - return nil, err - } - return &FsManifestsSaver{dir: manifestDir}, nil -}