This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New command: skuba addon refresh localconfig (bsc#1173055) (#1226)
Implements skuba addon refresh localconfig, related bugzilla . bsc#1173055 . bsc#1172805 Signed-off-by: JenTing Hsiao <jenting.hsiao@suse.com>
- Loading branch information
JenTing Hsiao
authored
Jul 13, 2020
1 parent
bb9a473
commit d3c5001
Showing
7 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2020 SUSE LLC. | ||
* | ||
* 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 addons | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/klog" | ||
|
||
"github.com/SUSE/skuba/internal/pkg/skuba/kubernetes" | ||
addons "github.com/SUSE/skuba/pkg/skuba/actions/addon/refresh" | ||
) | ||
|
||
// NewRefreshCmd creates a new `skuba addon refresh` cobra command | ||
func NewRefreshCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "refresh", | ||
Short: "Manages addon refresh operations", | ||
} | ||
|
||
cmd.AddCommand( | ||
newRefreshLocalConfigCmd(), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
func newRefreshLocalConfigCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "localconfig", | ||
Short: "Update local cluster definition folder configuration", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
clientSet, err := kubernetes.GetAdminClientSet() | ||
if err != nil { | ||
klog.Errorf("unable to get admin client set: %s", err) | ||
os.Exit(1) | ||
} | ||
if err := addons.AddonsBaseManifest(clientSet); err != nil { | ||
fmt.Printf("Unable to update addons base manifests: %s\n", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
Args: cobra.NoArgs, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
% skuba-addon-refresh-localconfig(1) # skuba addon refresh localconfig - Update local addon definition folder configuration | ||
|
||
# NAME | ||
|
||
localconfig - Update local addon definition folder configuration | ||
|
||
# SYNOPSIS | ||
**localconfig** | ||
[**--help**|**-h**] | ||
*localconfig* [-h] | ||
|
||
# DESCRIPTION | ||
**localconfig** Update local addon definition folder configuration | ||
|
||
# OPTIONS | ||
|
||
**--help, -h** | ||
Print usage statement. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2020 SUSE LLC. | ||
* | ||
* 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 addons | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/SUSE/skuba/internal/pkg/skuba/kubernetes" | ||
skubaconstants "github.com/SUSE/skuba/pkg/skuba" | ||
) | ||
|
||
func TestAddonLegacyManifestMigration(t *testing.T) { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
t.Errorf("unable to get current directory: %v", err) | ||
return | ||
} | ||
|
||
defer func() { | ||
// removes rendered addon folder | ||
dir := filepath.Join(pwd, "addons") | ||
if f, err := os.Stat(dir); !os.IsNotExist(err) && f.IsDir() { | ||
if err := os.RemoveAll(dir); err != nil { | ||
t.Errorf("unable to remove rendered addon folder: %v", err) | ||
return | ||
} | ||
} | ||
}() | ||
|
||
// create legacy addons manifest folder | ||
if err := os.Mkdir(filepath.Join(pwd, skubaconstants.AddonsDir()), 0700); err != nil { | ||
t.Errorf("unable to create directory %s: %v", skubaconstants.AddonsDir(), err) | ||
return | ||
} | ||
for _, addon := range Addons { | ||
addonDir := filepath.Join(pwd, addon.addonDir()) | ||
if err := os.Mkdir(addonDir, 0700); err != nil { | ||
t.Errorf("unable to create directory %s: %v", addonDir, err) | ||
return | ||
} | ||
lagacyManifestPath := addon.legacyManifestPath(addonDir) | ||
if err := ioutil.WriteFile(lagacyManifestPath, []byte(""), 0600); err != nil { | ||
t.Errorf("unable to write legacy addon manifest: %v", err) | ||
return | ||
} | ||
} | ||
|
||
addonConfiguration := AddonConfiguration{ | ||
ClusterVersion: kubernetes.LatestVersion(), | ||
ControlPlane: "unit.test", | ||
ClusterName: "unit-test", | ||
} | ||
// render new addons manifest folder | ||
for _, addon := range Addons { | ||
if err := addon.Write(addonConfiguration); err != nil { | ||
t.Errorf("expected no error, but got error: %v", err) | ||
return | ||
} | ||
} | ||
|
||
// check the legacy addons manifest gone | ||
for _, addon := range Addons { | ||
lagacyManifestPath := addon.legacyManifestPath(filepath.Join(pwd, addon.addonDir())) | ||
if _, err := os.Stat(lagacyManifestPath); !os.IsNotExist(err) { | ||
t.Error("expected legacy manifest not exists") | ||
return | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2020 SUSE LLC. | ||
* | ||
* 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 refresh | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
clientset "k8s.io/client-go/kubernetes" | ||
|
||
"github.com/SUSE/skuba/internal/pkg/skuba/addons" | ||
"github.com/SUSE/skuba/internal/pkg/skuba/kubeadm" | ||
) | ||
|
||
// AddonsBaseManifest implements the `skuba addon refresh localconfig` command. | ||
func AddonsBaseManifest(client clientset.Interface) error { | ||
currentClusterVersion, err := kubeadm.GetCurrentClusterVersion(client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clusterConfiguration, err := kubeadm.GetClusterConfiguration(client) | ||
if err != nil { | ||
return errors.Wrap(err, "Could not fetch cluster configuration") | ||
} | ||
|
||
// re-render all addons manifest | ||
addonConfiguration := addons.AddonConfiguration{ | ||
ClusterVersion: currentClusterVersion, | ||
ControlPlane: clusterConfiguration.ControlPlaneEndpoint, | ||
ClusterName: clusterConfiguration.ClusterName, | ||
} | ||
for addonName, addon := range addons.Addons { | ||
if err := addon.Write(addonConfiguration); err != nil { | ||
return errors.Wrapf(err, "failed to refresh addon %s manifest", string(addonName)) | ||
} | ||
} | ||
|
||
fmt.Println("Successfully refreshed addons base manifests") | ||
return nil | ||
} |