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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1098,8 +1098,6 @@ openslides-cli/
│ │ │ ├── health.go
│ │ │ ├── health_check.go
│ │ │ ├── health_check_test.go
│ │ │ ├── helpers.go
│ │ │ ├── helpers_test.go
│ │ │ ├── scale.go
│ │ │ ├── start.go
│ │ │ ├── stop.go
Expand Down
3 changes: 2 additions & 1 deletion internal/k8s/actions/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -107,7 +108,7 @@ func applyDirectory(ctx context.Context, k8sClient *client.Client, dirPath strin
continue
}

if !isYAMLFile(file.Name()) {
if !utils.IsYAMLFile(file.Name()) {
logger.Debug("Skipping non-YAML file: %s", file.Name())
continue
}
Expand Down
3 changes: 2 additions & 1 deletion internal/k8s/actions/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/OpenSlides/openslides-cli/internal/constants"
"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -34,7 +35,7 @@ func HealthCmd() *cobra.Command {
cmd.RunE = func(cmd *cobra.Command, args []string) error {
logger.Info("=== K8S HEALTH CHECK ===")
instanceDir := args[0]
namespace := extractNamespace(instanceDir)
namespace := utils.ExtractNamespace(instanceDir)
logger.Debug("Namespace: %s", namespace)

k8sClient, err := client.New(*kubeconfig)
Expand Down
27 changes: 0 additions & 27 deletions internal/k8s/actions/helpers.go

This file was deleted.

125 changes: 0 additions & 125 deletions internal/k8s/actions/helpers_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion internal/k8s/actions/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/OpenSlides/openslides-cli/internal/constants"
"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -49,7 +50,7 @@ func ScaleCmd() *cobra.Command {
logger.Debug("Instance directory: %s", instanceDir)
logger.Info("Service: %s", *service)

namespace := extractNamespace(instanceDir)
namespace := utils.ExtractNamespace(instanceDir)
logger.Info("Namespace: %s", namespace)

k8sClient, err := client.New(*kubeconfig)
Expand Down
7 changes: 6 additions & 1 deletion internal/k8s/actions/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/OpenSlides/openslides-cli/internal/constants"
"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -53,7 +54,11 @@ func StartCmd() *cobra.Command {
logger.Info("Applied namespace: %s", namespace)

tlsSecretPath := filepath.Join(instanceDir, constants.SecretsDirName, constants.TlsCertSecretYAML)
if fileExists(tlsSecretPath) {
tlsExists, err := utils.FileExists(tlsSecretPath)
if err != nil {
return fmt.Errorf("checking tls secret path %s: %w", tlsSecretPath, err)
}
if tlsExists {
logger.Info("Found and applying %s", tlsSecretPath)
if _, err := applyManifest(ctx, k8sClient, tlsSecretPath); err != nil {
return fmt.Errorf("applying TLS secret: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion internal/k8s/actions/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/OpenSlides/openslides-cli/internal/constants"
"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"
"github.com/spf13/cobra"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -49,7 +50,7 @@ func StopCmd() *cobra.Command {

ctx := context.Background()

namespace := extractNamespace(instanceDir)
namespace := utils.ExtractNamespace(instanceDir)
if err := saveTLSSecret(ctx, k8sClient, namespace, instanceDir); err != nil {
logger.Warn("Failed to save TLS secret: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/k8s/actions/update_backendmanage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/OpenSlides/openslides-cli/internal/constants"
"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -51,7 +52,7 @@ func UpdateBackendmanageCmd() *cobra.Command {

logger.Info("=== K8S UPDATE/REVERT BACKENDMANAGE ===")
instanceDir := args[0]
namespace := extractNamespace(instanceDir)
namespace := utils.ExtractNamespace(instanceDir)

logger.Info("Namespace: %s", namespace)

Expand Down
3 changes: 2 additions & 1 deletion internal/k8s/actions/update_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/OpenSlides/openslides-cli/internal/constants"
"github.com/OpenSlides/openslides-cli/internal/k8s/client"
"github.com/OpenSlides/openslides-cli/internal/logger"
"github.com/OpenSlides/openslides-cli/internal/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,7 +40,7 @@ func UpdateInstanceCmd() *cobra.Command {

logger.Debug("Instance directory: %s", instanceDir)

namespace := extractNamespace(instanceDir)
namespace := utils.ExtractNamespace(instanceDir)
logger.Info("Namespace: %s", namespace)

k8sClient, err := client.New(*kubeconfig)
Expand Down
20 changes: 18 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"io/fs"
"os"
"path"
"path/filepath"
"strings"

"github.com/OpenSlides/openslides-cli/internal/logger"
)
Expand All @@ -16,7 +18,7 @@ import (
func CreateFile(dir string, force bool, name string, content []byte, perm fs.FileMode) error {
p := path.Join(dir, name)

pExists, err := fileExists(p)
pExists, err := FileExists(p)
if err != nil {
return fmt.Errorf("checking file existance: %w", err)
}
Expand All @@ -33,7 +35,7 @@ func CreateFile(dir string, force bool, name string, content []byte, perm fs.Fil

// fileExists is a small helper function to check if a file already exists. It is not
// save in concurrent usage.
func fileExists(p string) (bool, error) {
func FileExists(p string) (bool, error) {
_, err := os.Stat(p)
if err == nil {
return true, nil
Expand Down Expand Up @@ -104,3 +106,17 @@ func ReadPassword(passwordFile string) (string, error) {
logger.Debug("Password read successfully (%d bytes)", len(password))
return password, nil
}

// extractNamespace gets the namespace from instance directory path
// Example: "/real/path/to/my.instance.dir.url" -> "myinstancedirurl"
func ExtractNamespace(instanceDir string) string {
dirName := filepath.Base(instanceDir)
namespace := strings.ReplaceAll(dirName, ".", "")
return namespace
}

// isYAMLFile checks if filename has YAML extension
func IsYAMLFile(filename string) bool {
ext := filepath.Ext(filename)
return ext == ".yaml" || ext == ".yml"
}
Loading