Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add upgrade (also major) and inspect command #123

Merged
merged 30 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7acfaf5
add functions for managing pods and containers
mbussolotto Feb 7, 2024
7426dc5
move function to shared code
mbussolotto Feb 7, 2024
363e088
Create inspect command
mbussolotto Jan 25, 2024
201c0a0
check if image tag is missing
mbussolotto Feb 7, 2024
11a5288
Create upgrade command
mbussolotto Jan 11, 2024
8997263
store image value in systemd conf file
mbussolotto Feb 7, 2024
057a09f
add files generated by vim-go to .gitignore
mbussolotto Feb 7, 2024
7bbeae1
upgrade and add missing copyright
mbussolotto Feb 7, 2024
914220c
inspect fqdn value and use it for kubernetes upgrade
mbussolotto Feb 7, 2024
8b4db0b
wait for replica
mbussolotto Feb 7, 2024
f6f50a1
improve error handling
mbussolotto Feb 7, 2024
5e5a482
computeImage can append strings correctly
mbussolotto Feb 8, 2024
583e653
Improve log messages and error handling
mbussolotto Feb 8, 2024
12e7e3b
nobuild inspect for k8s
mbussolotto Feb 8, 2024
e1d20b5
use shared podman for ServerContainerName
mbussolotto Feb 8, 2024
ae291ca
Update utils.go
mbussolotto Feb 8, 2024
0ca4f7b
override deployment in a cleaner way
mbussolotto Feb 9, 2024
3600fab
unique function for inspect
mbussolotto Feb 9, 2024
15f56fd
add golangci-lint and fix all the current errors
mbussolotto Feb 9, 2024
91106bb
Update shared/kubernetes/utils.go
mbussolotto Feb 13, 2024
45a6c08
DeletePod do not return output
mbussolotto Feb 13, 2024
831c90e
fix gofmt
mbussolotto Feb 13, 2024
c39c91b
check if pod is running before delete it
mbussolotto Feb 13, 2024
9762a30
add ineffassign lint and fix the errors
mbussolotto Feb 13, 2024
55cccf0
enable staticheck and fix existing errors
mbussolotto Feb 13, 2024
7e4a492
add test for multiple imports and fix the existing errors
mbussolotto Feb 13, 2024
3a8e7c4
remove duplicated line on debug logs
mbussolotto Feb 13, 2024
7603f2d
implement wait for replica when replica == 0
mbussolotto Feb 13, 2024
f6ce254
gently defer
mbussolotto Feb 13, 2024
a80c6a2
suma changes
mbussolotto Feb 20, 2024
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
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
Loading