Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/k0s"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/spf13/cobra"
)
Expand All @@ -26,5 +27,5 @@ func AddDownloadCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) {
util.AddCmd(rootCmd, download.cmd)

AddDownloadPackageCmd(download.cmd, opts)
AddDownloadK0sCmd(download.cmd, opts)
k0s.AddDownloadCmd(download.cmd, opts)
}
3 changes: 2 additions & 1 deletion cli/cmd/init_install_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/codesphere-cloud/oms/cli/cmd/testutil"
"github.com/codesphere-cloud/oms/internal/installer"
"github.com/codesphere-cloud/oms/internal/installer/files"
"github.com/codesphere-cloud/oms/internal/installer/vault"
Expand Down Expand Up @@ -216,7 +217,7 @@ codesphere:

Context("valid configuration", func() {
It("validates successfully", func() {
if !sopsAndAgeAvailableForUpdateInstallConfig() {
if !testutil.SopsAndAgeAvailable() {
Skip("sops and age-keygen not available")
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/codesphere"
"github.com/codesphere-cloud/oms/cli/cmd/k0s"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/spf13/cobra"
)
Expand All @@ -26,6 +27,6 @@ func AddInstallCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) {
util.AddCmd(rootCmd, install.cmd)

codesphere.AddInstallCmd(install.cmd, opts)
AddInstallK0sCmd(install.cmd, opts)
k0s.AddInstallCmd(install.cmd, opts)
AddInstallOpenBaoCmd(install.cmd, opts)
}
4 changes: 2 additions & 2 deletions cli/cmd/download_k0s.go → cli/cmd/k0s/download_k0s.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd
package k0s

import (
"fmt"
Expand Down Expand Up @@ -45,7 +45,7 @@ func (c *DownloadK0sCmd) RunE(_ *cobra.Command, args []string) error {
return nil
}

func AddDownloadK0sCmd(download *cobra.Command, opts *util.GlobalOptions) {
func AddDownloadCmd(download *cobra.Command, opts *util.GlobalOptions) {
k0s := DownloadK0sCmd{
cmd: &cobra.Command{
Use: "k0s",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd_test
package k0s_test

import (
"errors"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/codesphere-cloud/oms/cli/cmd"
"github.com/codesphere-cloud/oms/cli/cmd/k0s"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/env"
"github.com/codesphere-cloud/oms/internal/installer"
intutil "github.com/codesphere-cloud/oms/internal/util"
)

var _ = Describe("DownloadK0sCmd", func() {
var _ = Describe("DownloadK0sk0s", func() {
var (
c cmd.DownloadK0sCmd
opts *cmd.DownloadK0sOpts
c k0s.DownloadK0sCmd
opts *k0s.DownloadK0sOpts
globalOpts *util.GlobalOptions
mockEnv *env.MockEnv
mockFileWriter *intutil.MockFileIO
Expand All @@ -29,13 +29,13 @@ var _ = Describe("DownloadK0sCmd", func() {
mockEnv = env.NewMockEnv(GinkgoT())
mockFileWriter = intutil.NewMockFileIO(GinkgoT())
globalOpts = &util.GlobalOptions{}
opts = &cmd.DownloadK0sOpts{
opts = &k0s.DownloadK0sOpts{
GlobalOptions: globalOpts,
Version: "",
Force: false,
Quiet: false,
}
c = cmd.DownloadK0sCmd{
c = k0s.DownloadK0sCmd{
Opts: *opts,
Env: mockEnv,
FileWriter: mockFileWriter,
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/install_k0s.go → cli/cmd/k0s/install_k0s.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd
package k0s

import (
"fmt"
Expand Down Expand Up @@ -52,7 +52,7 @@ func (c *InstallK0sCmd) RunE(_ *cobra.Command, args []string) error {
return c.InstallK0s(pm, k0s, k0sctl)
}

func AddInstallK0sCmd(install *cobra.Command, opts *util.GlobalOptions) {
func AddInstallCmd(install *cobra.Command, opts *util.GlobalOptions) {
k0s := InstallK0sCmd{
cmd: &cobra.Command{
Use: "k0s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//go:build integration
// +build integration

package cmd_test
package k0s_test

import (
"fmt"
Expand Down
19 changes: 10 additions & 9 deletions cli/cmd/install_k0s_test.go → cli/cmd/k0s/install_k0s_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd_test
package k0s_test

import (
"os"
Expand All @@ -14,7 +14,8 @@ import (
"github.com/stretchr/testify/mock"
"gopkg.in/yaml.v3"

"github.com/codesphere-cloud/oms/cli/cmd"
"github.com/codesphere-cloud/oms/cli/cmd/k0s"
"github.com/codesphere-cloud/oms/cli/cmd/testutil"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/env"
"github.com/codesphere-cloud/oms/internal/installer"
Expand All @@ -30,8 +31,8 @@ func execCmd(name string, args ...string) ([]byte, error) {

var _ = Describe("InstallK0sCmd", func() {
var (
c cmd.InstallK0sCmd
opts *cmd.InstallK0sOpts
c k0s.InstallK0sCmd
opts *k0s.InstallK0sOpts
globalOpts *util.GlobalOptions
mockEnv *env.MockEnv
mockFileWriter *intutil.MockFileIO
Expand All @@ -41,14 +42,14 @@ var _ = Describe("InstallK0sCmd", func() {
mockEnv = env.NewMockEnv(GinkgoT())
mockFileWriter = intutil.NewMockFileIO(GinkgoT())
globalOpts = &util.GlobalOptions{}
opts = &cmd.InstallK0sOpts{
opts = &k0s.InstallK0sOpts{
GlobalOptions: globalOpts,
Version: "",
Package: "",
InstallConfig: "",
Force: false,
}
c = cmd.InstallK0sCmd{
c = k0s.InstallK0sCmd{
Opts: *opts,
Env: mockEnv,
FileWriter: mockFileWriter,
Expand Down Expand Up @@ -384,7 +385,7 @@ var _ = Describe("InstallK0sCmd", func() {
})

It("re-encrypts vault after saving kubeconfig when vault was SOPS-encrypted", func() {
if !sopsAndAgeAvailable() {
if !testutil.SopsAndAgeAvailable() {
Skip("sops and age-keygen not available")
}

Expand Down Expand Up @@ -451,7 +452,7 @@ var _ = Describe("InstallK0sCmd", func() {
})

It("leaves the vault untouched when vault decryption fails with invalid key", func() {
if !sopsAndAgeAvailable() {
if !testutil.SopsAndAgeAvailable() {
Skip("sops and age-keygen not available")
}

Expand Down Expand Up @@ -521,7 +522,7 @@ var _ = Describe("InstallK0sCmd", func() {
})

It("leaves the vault untouched when encryption of the new vault fails", func() {
if !sopsAndAgeAvailable() {
if !testutil.SopsAndAgeAvailable() {
Skip("sops and age-keygen not available")
}

Expand Down
13 changes: 2 additions & 11 deletions cli/cmd/template_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/codesphere-cloud/oms/cli/cmd"
"github.com/codesphere-cloud/oms/cli/cmd/testutil"
"github.com/codesphere-cloud/oms/internal/installer/files"
"github.com/codesphere-cloud/oms/internal/installer/vault"

Expand All @@ -20,7 +21,7 @@ import (

var _ = Describe("TemplateConfigCmd", func() {
It("renders config templates with secrets from a vault file", func() {
if !sopsAndAgeAvailable() {
if !testutil.SopsAndAgeAvailable() {
Skip("sops and age-keygen not available")
}

Expand Down Expand Up @@ -102,13 +103,3 @@ postgres:
Expect(configCmd.Flags().Lookup("age-key")).NotTo(BeNil())
})
})

func sopsAndAgeAvailable() bool {
if _, err := exec.LookPath("sops"); err != nil {
return false
}
if _, err := exec.LookPath("age-keygen"); err != nil {
return false
}
return true
}
16 changes: 16 additions & 0 deletions cli/cmd/testutil/testutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Codesphere Inc.
// SPDX-License-Identifier: Apache-2.0

package testutil

import "os/exec"

func SopsAndAgeAvailable() bool {
if _, err := exec.LookPath("sops"); err != nil {
return false
}
if _, err := exec.LookPath("age-keygen"); err != nil {
return false
}
return true
}
13 changes: 2 additions & 11 deletions cli/cmd/update_install_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/codesphere-cloud/oms/cli/cmd/testutil"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/installer"
"github.com/codesphere-cloud/oms/internal/installer/files"
Expand Down Expand Up @@ -41,7 +42,7 @@ var _ = Describe("UpdateInstallConfig", func() {
)

BeforeEach(func() {
if !sopsAndAgeAvailableForUpdateInstallConfig() {
if !testutil.SopsAndAgeAvailable() {
Skip("sops and age-keygen not available")
}

Expand Down Expand Up @@ -457,16 +458,6 @@ codesphere:
})
})

func sopsAndAgeAvailableForUpdateInstallConfig() bool {
if _, err := exec.LookPath("sops"); err != nil {
return false
}
if _, err := exec.LookPath("age-keygen"); err != nil {
return false
}
return true
}

var _ = Describe("SecretDependencyTracker", func() {
var tracker *SecretDependencyTracker

Expand Down
Loading