Skip to content

Commit

Permalink
Merge pull request #123 from mbussolotto/upgrade
Browse files Browse the repository at this point in the history
add upgrade (also major) and inspect command
  • Loading branch information
mbussolotto authored Feb 20, 2024
2 parents c389eed + a80c6a2 commit 0d8aa3f
Show file tree
Hide file tree
Showing 121 changed files with 2,459 additions and 523 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# SPDX-FileCopyrightText: 2024 SUSE LLC
#
# SPDX-License-Identifier: Apache-2.0

name: golangci-lint
on:
push:
branches:
- main
pull_request:

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ bin
vendor.tar.gz
*.pyc
__pycache__
tags
**/tags
89 changes: 89 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# SPDX-FileCopyrightText: 2024 SUSE LLC
#
# SPDX-License-Identifier: Apache-2.0

run:
tests: true
skip-dirs:
- vendor
- examples

linters-settings:
dupl:
enabled: true
errcheck:
enabled: true
gofmt:
enabled: true
simplify: true
goimports:
enabled: true
gocyclo:
enabled: true
min-complexity: 10
godot:
enabled: true
golint:
enabled: true
ineffassign:
enabled: true
maligned:
enabled: true
megacheck:
enabled: true
misspell:
enabled: true
revive:
rules:
- name: exported
arguments:
- disableStutteringCheck
staticcheck:
enabled: false
stylecheck:
enabled: true
checks: ["ST1005", "ST1019"]
structcheck:
enabled: true
typecheck:
enabled: true
unused:
enabled: true
varcheck:
enabled: true
whitespace:
enabled: true

linters:
disable-all: true
enable:
- unused
- dupl
- errcheck
- errname
#- errorlint
- godot
- gofmt
- goimports
- gosimple
#- gocyclo
- revive
- ineffassign
- govet
#- lll
#- megacheck
- misspell
- revive
#- staticcheck
- stylecheck
- typecheck
#- unparam
- unused
- whitespace

issues:
include:
- EXC0012



7 changes: 5 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/bash

# SPDX-FileCopyrightText: 2023 SUSE LLC
# SPDX-FileCopyrightText: 2024 SUSE LLC
#
# SPDX-License-Identifier: Apache-2.0

set -e
mkdir -p ./bin

tag=$(git describe --tags --abbrev=0)
Expand All @@ -22,3 +22,6 @@ for shell in "bash" "zsh" "fish"; do
./bin/mgrctl completion ${shell} >> "${COMPLETION_FILE}"
./bin/mgrpxy completion ${shell} >> "${COMPLETION_FILE}"
done

golangci-lint run
echo "DONE"
24 changes: 18 additions & 6 deletions mgradm/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 SUSE LLC
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -15,17 +15,19 @@ import (
"github.com/uyuni-project/uyuni-tools/shared/utils"

"github.com/uyuni-project/uyuni-tools/mgradm/cmd/distro"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/inspect"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/install"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/migrate"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/restart"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/start"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/stop"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/support"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/uninstall"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/upgrade"
)

// NewCommand returns a new cobra.Command implementing the root command for kinder
func NewUyuniadmCommand() *cobra.Command {
// NewCommand returns a new cobra.Command implementing the root command for kinder.
func NewUyuniadmCommand() (*cobra.Command, error) {
globalFlags := &types.GlobalFlags{}
name := path.Base(os.Args[0])
rootCmd := &cobra.Command{
Expand All @@ -36,7 +38,11 @@ func NewUyuniadmCommand() *cobra.Command {
SilenceUsage: true, // Don't show usage help on errors
}

rootCmd.SetUsageTemplate(utils.GetUsageWithConfigHelpTemplate(rootCmd.UsageTemplate()))
usage, err := utils.GetUsageWithConfigHelpTemplate(rootCmd.UsageTemplate())
if err != nil {
return rootCmd, err
}
rootCmd.SetUsageTemplate(usage)

rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
utils.LogInit(true)
Expand All @@ -59,12 +65,18 @@ func NewUyuniadmCommand() *cobra.Command {
rootCmd.AddCommand(installCmd)

rootCmd.AddCommand(uninstall.NewCommand(globalFlags))
rootCmd.AddCommand(distro.NewCommand(globalFlags))
distroCmd, err := distro.NewCommand(globalFlags)
if err != nil {
return rootCmd, err
}
rootCmd.AddCommand(distroCmd)
rootCmd.AddCommand(completion.NewCommand(globalFlags))
rootCmd.AddCommand(support.NewCommand(globalFlags))
rootCmd.AddCommand(start.NewCommand(globalFlags))
rootCmd.AddCommand(restart.NewCommand(globalFlags))
rootCmd.AddCommand(stop.NewCommand(globalFlags))
rootCmd.AddCommand(inspect.NewCommand(globalFlags))
rootCmd.AddCommand(upgrade.NewCommand(globalFlags))

return rootCmd
return rootCmd, err
}
23 changes: 13 additions & 10 deletions mgradm/cmd/distro/cp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-FileCopyrightText: 2023 SUSE LLC
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

package distro

import (
"errors"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -47,10 +49,9 @@ func registerDistro(connection *api.ConnectionDetails, distro *types.Distributio

_, err = client.Post("kickstart/tree/create", data)
if err != nil {
log.Error().Msg("Unable to register the distribution. Manual distro registration is required.")
return err
return fmt.Errorf("unable to register the distribution. Manual distro registration is required: %s", err)
}
log.Info().Msgf("Distribution %s successfuly registered", distro.TreeLabel)
log.Info().Msgf("Distribution %s successfully registered", distro.TreeLabel)
return nil
}

Expand All @@ -72,20 +73,20 @@ func distroCp(
cnx := shared.NewConnection(flags.Backend, podman.ServerContainerName, kubernetes.ServerFilter)
log.Info().Msgf("Copying distribution %s\n", distroName)
if !utils.FileExists(source) {
log.Fatal().Msgf("Source %s does not exists", source)
return fmt.Errorf("source %s does not exists", source)
}

dstpath := "/srv/www/distributions/" + distroName
if cnx.TestExistenceInPod(dstpath) {
log.Fatal().Msgf("Distribution already exists: %s\n", dstpath)
return fmt.Errorf("distribution already exists: %s", dstpath)
}

srcdir := source
if strings.HasSuffix(source, ".iso") {
log.Debug().Msg("Source is an iso file")
tmpdir, err := os.MkdirTemp("", "mgrctl")
if err != nil {
log.Fatal().Err(err)
return err
}
srcdir = tmpdir
defer umountAndRemove(srcdir)
Expand All @@ -98,11 +99,13 @@ func distroCp(
}
if out, err := utils.RunCmdOutput(zerolog.DebugLevel, "/usr/bin/sudo", mountCmd...); err != nil {
log.Debug().Msgf("Error mounting iso: '%s'", out)
log.Error().Msg("Unable to mount iso file. Mount manually and try again")
return errors.New("unable to mount iso file. Mount manually and try again")
}
}

cnx.Copy(srcdir, "server:"+dstpath, "tomcat", "susemanager")
if err := cnx.Copy(srcdir, "server:"+dstpath, "tomcat", "susemanager"); err != nil {
return fmt.Errorf("cannot copy %s: %s", dstpath, err)
}

log.Info().Msg("Distribution has been copied")

Expand All @@ -115,7 +118,7 @@ func distroCp(
}

if err := registerDistro(&flags.ConnectionDetails, &distro); err != nil {
log.Error().Msg(err.Error())
return err
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/distro/detect.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 SUSE LLC
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -80,7 +80,7 @@ func getDistroFromDetails(distro string, version string, arch string, channeLabe
}

if !ok {
return types.Distribution{}, fmt.Errorf("unkown distribution, auto-registration is not possible")
return types.Distribution{}, fmt.Errorf("unknown distribution, auto-registration is not possible")
}

if channeLabel != "" {
Expand Down
11 changes: 7 additions & 4 deletions mgradm/cmd/distro/distro.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 SUSE LLC
// SPDX-FileCopyrightText: 2024 SUSE LLC
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -18,7 +18,8 @@ type flagpole struct {
ConnectionDetails api.ConnectionDetails `mapstructure:"api"`
}

func NewCommand(globalFlags *types.GlobalFlags) *cobra.Command {
// NewCommand command for distribution management.
func NewCommand(globalFlags *types.GlobalFlags) (*cobra.Command, error) {
var flags flagpole

distroCmd := &cobra.Command{
Expand All @@ -43,7 +44,9 @@ Optional channel label specify which parent channel to associate with the distri
},
}

api.AddAPIFlags(distroCmd, true)
if err := api.AddAPIFlags(distroCmd, true); err != nil {
return distroCmd, err
}
distroCmd.AddCommand(cpCmd)
return distroCmd
return distroCmd, nil
}
Loading

0 comments on commit 0d8aa3f

Please sign in to comment.