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
13 changes: 7 additions & 6 deletions cli/cmd/add_cluster_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"fmt"

packageio "github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/clusteradmin"
"github.com/codesphere-cloud/oms/internal/util"
intutil "github.com/codesphere-cloud/oms/internal/util"
"github.com/spf13/cobra"
)

Expand All @@ -18,20 +19,20 @@ type AddClusterAdminCmd struct {
}

type AddClusterAdminOpts struct {
*GlobalOptions
*util.GlobalOptions
clusteradmin.Opts
}

func (c *AddClusterAdminCmd) RunE(_ *cobra.Command, _ []string) error {
clientset, _, err := util.NewClients()
clientset, _, err := intutil.NewClients()
if err != nil {
return fmt.Errorf("failed to create kubernetes client: %w", err)
}

return clusteradmin.AddClusterAdmin(c.cmd.Context(), clientset, c.Opts.Opts)
}

func AddAddClusterAdminCmd(parent *cobra.Command, opts *GlobalOptions) {
func AddAddClusterAdminCmd(parent *cobra.Command, opts *util.GlobalOptions) {
c := AddClusterAdminCmd{
cmd: &cobra.Command{
Use: "add-cluster-admin",
Expand All @@ -43,7 +44,7 @@ func AddAddClusterAdminCmd(parent *cobra.Command, opts *GlobalOptions) {

The target cluster is determined by the current kubeconfig context. Set the KUBECONFIG
environment variable to target a different kubeconfig.`),
Example: formatExamples("add-cluster-admin", []packageio.Example{
Example: util.FormatExamples("add-cluster-admin", []packageio.Example{
{Cmd: "--email niklas@codesphere.com", Desc: "Set the cluster admin email using the default secret and namespace"},
{Cmd: "--email admin@codesphere.com --namespace kube-system --secret-name cluster-admin-email", Desc: "Set the cluster admin email in a custom namespace"},
}),
Expand All @@ -59,5 +60,5 @@ func AddAddClusterAdminCmd(parent *cobra.Command, opts *GlobalOptions) {

util.MarkFlagRequired(c.cmd, "email")

AddCmd(parent, c.cmd)
util.AddCmd(parent, c.cmd)
}
9 changes: 5 additions & 4 deletions cli/cmd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

packageio "github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
argocdinstaller "github.com/codesphere-cloud/oms/internal/installer/argocd"
"github.com/spf13/cobra"
"golang.org/x/term"
Expand All @@ -20,7 +21,7 @@ type InstallArgoCDCmd struct {
}

type InstallArgoCDOpts struct {
*GlobalOptions
*util.GlobalOptions
Version string
DatacenterId string
RegistryURL string
Expand Down Expand Up @@ -87,7 +88,7 @@ func resolveOCIPassword() (string, error) {
return string(pw), nil
}

func AddArgoCDCmd(parentCmd *cobra.Command, opts *GlobalOptions) {
func AddArgoCDCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) {
argocd := InstallArgoCDCmd{
cmd: &cobra.Command{
Use: "argocd",
Expand All @@ -106,7 +107,7 @@ func AddArgoCDCmd(parentCmd *cobra.Command, opts *GlobalOptions) {
Environment variables:
OMS_REGISTRY_PASSWORD Password/token for the Helm OCI registry (required for --deploy-dc-config)
OMS_GIT_PASSWORD Password/token for git repo access (optional)`),
Example: formatExamples("beta install argocd", []packageio.Example{
Example: util.FormatExamples("beta install argocd", []packageio.Example{
{Cmd: "", Desc: "Install ArgoCD helm chart only"},
{Cmd: "--version 7.8.0", Desc: "Install a specific chart version"},
{Cmd: "--deploy-dc-config", Desc: "Install chart and apply Codesphere resources (prompts for OCI password)"},
Expand All @@ -123,5 +124,5 @@ func AddArgoCDCmd(parentCmd *cobra.Command, opts *GlobalOptions) {
argocd.cmd.Flags().StringVar(&argocd.Opts.RepoURL, "repo", "", "Helm chart repository URL; supports HTTP (default: https://argoproj.github.io/argo-helm) and OCI (e.g. oci://ghcr.io/argoproj/argo-helm)")
argocd.cmd.RunE = argocd.RunE

AddCmd(parentCmd, argocd.cmd)
util.AddCmd(parentCmd, argocd.cmd)
}
5 changes: 3 additions & 2 deletions cli/cmd/beta.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ package cmd

import (
"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/spf13/cobra"
)

type BetaCmd struct {
cmd *cobra.Command
}

func AddBetaCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
func AddBetaCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) {
beta := BetaCmd{
cmd: &cobra.Command{
Use: "beta",
Expand All @@ -21,7 +22,7 @@ func AddBetaCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
Be aware that that usage and behavior may change as the features are developed.`),
},
}
AddCmd(rootCmd, beta.cmd)
util.AddCmd(rootCmd, beta.cmd)

AddExtendCmd(beta.cmd, opts)
AddBootstrapGcpCmd(beta.cmd, opts)
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/beta_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package cmd

import (
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/spf13/cobra"
)

Expand All @@ -12,14 +13,14 @@ type BetaInstallCmd struct {
cmd *cobra.Command
}

func AddBetaInstallCmd(rootCmd *cobra.Command, opts *GlobalOptions) {
func AddBetaInstallCmd(rootCmd *cobra.Command, opts *util.GlobalOptions) {
install := BetaInstallCmd{
cmd: &cobra.Command{
Use: "install",
Short: "Install beta components",
},
}
AddCmd(rootCmd, install.cmd)
util.AddCmd(rootCmd, install.cmd)
AddArgoCDCmd(install.cmd, opts)
AddPCAppsCmd(install.cmd, opts)
}
10 changes: 5 additions & 5 deletions cli/cmd/beta_vault_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

packageio "github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/installer/vault"
"github.com/codesphere-cloud/oms/internal/util"
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand All @@ -22,7 +22,7 @@ type BetaVaultSecretCmd struct {
}

type BetaVaultSecretOpts struct {
*GlobalOptions
*util.GlobalOptions
VaultFile string
AgeKeyPath string
Namespace string
Expand Down Expand Up @@ -50,15 +50,15 @@ func (c *BetaVaultSecretCmd) RunE(_ *cobra.Command, _ []string) error {
return creator.CreateSecretFromFile(c.cmd.Context(), c.Opts.VaultFile, c.Opts.AgeKeyPath, c.Opts.Namespace, c.Opts.SecretName)
}

func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *GlobalOptions) {
func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *util.GlobalOptions) {
cmd := BetaVaultSecretCmd{
cmd: &cobra.Command{
Use: "vault-secret",
Short: "Create a Kubernetes secret from a SOPS-encrypted vault file",
Long: packageio.Long(`Create a Kubernetes secret from a SOPS-encrypted prod.vault.yaml file.
Reads the encrypted vault file, decrypts it using the age key, and creates a Kubernetes secret
with all the vault entries as key-value pairs in the target cluster.`),
Example: formatExamples("vault-secret", []packageio.Example{
Example: util.FormatExamples("vault-secret", []packageio.Example{
{Cmd: "--vault-file prod.vault.yaml --namespace default --secret-name vault-secrets", Desc: "Create secret using default age key location"},
{Cmd: "--vault-file prod.vault.yaml --age-key /path/to/age_key.txt --namespace kube-system --secret-name cluster-secrets", Desc: "Create secret with explicit age key path"},
}),
Expand All @@ -74,5 +74,5 @@ func AddBetaVaultSecretCmd(parentCmd *cobra.Command, opts *GlobalOptions) {
util.MarkFlagRequired(cmd.cmd, "vault-file")

cmd.cmd.RunE = cmd.RunE
AddCmd(parentCmd, cmd.cmd)
util.AddCmd(parentCmd, cmd.cmd)
}
13 changes: 7 additions & 6 deletions cli/cmd/bootstrap_gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import (
"github.com/spf13/cobra"

"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/bootstrap"
"github.com/codesphere-cloud/oms/internal/bootstrap/gcp"
"github.com/codesphere-cloud/oms/internal/env"
"github.com/codesphere-cloud/oms/internal/github"
"github.com/codesphere-cloud/oms/internal/installer"
"github.com/codesphere-cloud/oms/internal/installer/node"
"github.com/codesphere-cloud/oms/internal/portal"
"github.com/codesphere-cloud/oms/internal/util"
intutil "github.com/codesphere-cloud/oms/internal/util"
)

type BootstrapGcpCmd struct {
cmd *cobra.Command
Opts *GlobalOptions
Opts *util.GlobalOptions
Env env.Env
CodesphereEnv *gcp.CodesphereEnvironment
InputRegistryType string
Expand All @@ -42,7 +43,7 @@ func (c *BootstrapGcpCmd) RunE(_ *cobra.Command, args []string) error {
return nil
}

func AddBootstrapGcpCmd(parent *cobra.Command, opts *GlobalOptions) {
func AddBootstrapGcpCmd(parent *cobra.Command, opts *util.GlobalOptions) {
bootstrapGcpCmd := BootstrapGcpCmd{
cmd: &cobra.Command{
Use: "bootstrap-gcp",
Expand Down Expand Up @@ -139,7 +140,7 @@ func AddBootstrapGcpCmd(parent *cobra.Command, opts *GlobalOptions) {
util.MarkFlagRequired(bootstrapGcpCmd.cmd, "billing-account")
util.MarkFlagRequired(bootstrapGcpCmd.cmd, "base-domain")

AddCmd(parent, bootstrapGcpCmd.cmd)
util.AddCmd(parent, bootstrapGcpCmd.cmd)
AddBootstrapGcpPostconfigCmd(bootstrapGcpCmd.cmd, opts)
AddBootstrapGcpCleanupCmd(bootstrapGcpCmd.cmd, opts)
AddBootstrapGcpRestartVMsCmd(bootstrapGcpCmd.cmd, opts)
Expand All @@ -150,7 +151,7 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
stlog := bootstrap.NewStepLogger(false)
icg := installer.NewInstallConfigManager()
gcpClient := gcp.NewGCPClient(ctx, stlog, os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
fw := util.NewFilesystemWriter()
fw := intutil.NewFilesystemWriter()
portalClient := portal.NewPortalClient()
githubClient := github.NewGitHubClient(ctx, c.CodesphereEnv.GitHubPAT)

Expand All @@ -164,7 +165,7 @@ func (c *BootstrapGcpCmd) BootstrapGcp() error {
fw,
node.NewSSHNodeClient(c.SSHQuiet),
portalClient,
util.NewTime(),
intutil.NewTime(),
githubClient,
)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions cli/cmd/bootstrap_gcp_cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"os"

csio "github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/bootstrap"
"github.com/codesphere-cloud/oms/internal/bootstrap/gcp"
"github.com/codesphere-cloud/oms/internal/util"
intutil "github.com/codesphere-cloud/oms/internal/util"
"github.com/spf13/cobra"
)

Expand All @@ -21,7 +22,7 @@ type BootstrapGcpCleanupCmd struct {
}

type BootstrapGcpCleanupOpts struct {
*GlobalOptions
*util.GlobalOptions
ProjectID string
Force bool
SkipDNSCleanup bool
Expand All @@ -34,7 +35,7 @@ func (c *BootstrapGcpCleanupCmd) RunE(_ *cobra.Command, args []string) error {
ctx := c.cmd.Context()
stlog := bootstrap.NewStepLogger(false)
gcpClient := gcp.NewGCPClient(ctx, stlog, os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))
fw := util.NewFilesystemWriter()
fw := intutil.NewFilesystemWriter()

deps := &gcp.CleanupDeps{
GCPClient: gcpClient,
Expand Down Expand Up @@ -88,13 +89,13 @@ func (c *BootstrapGcpCleanupCmd) ExecuteCleanup(deps *gcp.CleanupDeps) error {
return nil
}

func AddBootstrapGcpCleanupCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) {
func AddBootstrapGcpCleanupCmd(bootstrapGcp *cobra.Command, opts *util.GlobalOptions) {
cleanup := BootstrapGcpCleanupCmd{
cmd: &cobra.Command{
Use: "cleanup",
Short: "Clean up GCP infrastructure created by bootstrap-gcp",
Long: csio.Long(`Deletes a GCP project that was previously created using the bootstrap-gcp command.`),
Example: formatExamples("beta bootstrap-gcp cleanup", []csio.Example{
Example: util.FormatExamples("beta bootstrap-gcp cleanup", []csio.Example{
{Desc: "Clean up using project ID from the local infra file"},
{Cmd: "--project-id my-project-abc123", Desc: "Clean up a specific project"},
{Cmd: "--project-id my-project-abc123 --force", Desc: "Force cleanup without confirmation (skips OMS-managed check)"},
Expand All @@ -116,5 +117,5 @@ func AddBootstrapGcpCleanupCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions)
flags.StringVar(&cleanup.Opts.DNSProjectID, "dns-project-id", "", "GCP Project ID for DNS zone (optional, will use infra file if not provided)")

cleanup.cmd.RunE = cleanup.RunE
AddCmd(bootstrapGcp, cleanup.cmd)
util.AddCmd(bootstrapGcp, cleanup.cmd)
}
13 changes: 7 additions & 6 deletions cli/cmd/bootstrap_gcp_cleanup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ import (
"github.com/spf13/cobra"

"github.com/codesphere-cloud/oms/cli/cmd"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/bootstrap"
"github.com/codesphere-cloud/oms/internal/bootstrap/gcp"
"github.com/codesphere-cloud/oms/internal/util"
intutil "github.com/codesphere-cloud/oms/internal/util"
)

var _ = Describe("BootstrapGcpCleanupCmd", func() {
var (
opts *cmd.BootstrapGcpCleanupOpts
globalOpts *cmd.GlobalOptions
globalOpts *util.GlobalOptions
)

BeforeEach(func() {
globalOpts = &cmd.GlobalOptions{}
globalOpts = &util.GlobalOptions{}
opts = &cmd.BootstrapGcpCleanupOpts{
GlobalOptions: globalOpts,
ProjectID: "",
Expand Down Expand Up @@ -142,7 +143,7 @@ var _ = Describe("BootstrapGcpCleanupCmd", func() {
Context("when created", func() {
It("should hold all required dependencies", func() {
mockGCPClient := gcp.NewMockGCPClientManager(GinkgoT())
mockFileIO := util.NewMockFileIO(GinkgoT())
mockFileIO := intutil.NewMockFileIO(GinkgoT())
stlog := bootstrap.NewStepLogger(false)
confirmReader := bytes.NewBufferString("test-project\n")

Expand All @@ -167,13 +168,13 @@ var _ = Describe("BootstrapGcpCleanupCmd", func() {
var (
cleanupCmd *cmd.BootstrapGcpCleanupCmd
mockGCPClient *gcp.MockGCPClientManager
mockFileIO *util.MockFileIO
mockFileIO *intutil.MockFileIO
deps *gcp.CleanupDeps
)

BeforeEach(func() {
mockGCPClient = gcp.NewMockGCPClientManager(GinkgoT())
mockFileIO = util.NewMockFileIO(GinkgoT())
mockFileIO = intutil.NewMockFileIO(GinkgoT())

cleanupCmd = &cmd.BootstrapGcpCleanupCmd{
Opts: &cmd.BootstrapGcpCleanupOpts{
Expand Down
11 changes: 6 additions & 5 deletions cli/cmd/bootstrap_gcp_postconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"log"

"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/codesphere-cloud/oms/cli/cmd/util"
"github.com/codesphere-cloud/oms/internal/bootstrap/gcp"
"github.com/codesphere-cloud/oms/internal/installer"
"github.com/codesphere-cloud/oms/internal/util"
intutil "github.com/codesphere-cloud/oms/internal/util"
"github.com/spf13/cobra"
)

Expand All @@ -22,7 +23,7 @@ type BootstrapGcpPostconfigCmd struct {
}

type BootstrapGcpPostconfigOpts struct {
*GlobalOptions
*util.GlobalOptions
InstallConfigPath string
PrivateKeyPath string
}
Expand All @@ -31,7 +32,7 @@ func (c *BootstrapGcpPostconfigCmd) RunE(_ *cobra.Command, args []string) error
log.Printf("running post-configuration steps...")

icg := installer.NewInstallConfigManager()
fw := util.NewFilesystemWriter()
fw := intutil.NewFilesystemWriter()

infraFilePath := gcp.GetInfraFilePath()
codesphereEnv, exists, err := gcp.LoadInfraFile(fw, infraFilePath)
Expand All @@ -51,7 +52,7 @@ func (c *BootstrapGcpPostconfigCmd) RunE(_ *cobra.Command, args []string) error
return fmt.Errorf("not implemented: run config script on k0s-1 node to install GCP CCM")
}

func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *GlobalOptions) {
func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *util.GlobalOptions) {
postconfig := BootstrapGcpPostconfigCmd{
cmd: &cobra.Command{
Use: "postconfig",
Expand All @@ -70,6 +71,6 @@ func AddBootstrapGcpPostconfigCmd(bootstrapGcp *cobra.Command, opts *GlobalOptio
flags.StringVar(&postconfig.Opts.InstallConfigPath, "install-config-path", "config.yaml", "Path to the installation configuration file")
flags.StringVar(&postconfig.Opts.PrivateKeyPath, "private-key-path", "", "Path to the GCP service account private key file (optional)")

AddCmd(bootstrapGcp, postconfig.cmd)
util.AddCmd(bootstrapGcp, postconfig.cmd)
postconfig.cmd.RunE = postconfig.RunE
}
Loading
Loading