-
Notifications
You must be signed in to change notification settings - Fork 19
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
Kubernetes refactoring #450
Open
cbosdo
wants to merge
20
commits into
uyuni-project:main
Choose a base branch
from
cbosdo:k8s-refactoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c39b6e5
Kubernetes support for Hub XML-RPC
nadvornik 0482408
Backup the pgsql data after rsyncing them
cbosdo e9a44a0
Refresh the connection after the k8s migration
cbosdo e3b2544
Wait for 3 hours when running a pod
cbosdo 7560bc1
Add deployments reason for helm history
cbosdo 38864fb
Add crds.keep value for cert-manager to keep feature parity with inst…
cbosdo 152ed66
Reorganize the kubernetes SSL CA deployment code for readability
cbosdo 823bff1
Ports internal data description refactoring
cbosdo f6a60ce
Refactor the upgrade SanityCheck to not exec in a running container
cbosdo 475be63
Use one data structure for install, migrate, upgrade flags
cbosdo a04242d
Kubernetes migration refactoring
cbosdo 0a7d697
Move the RunSetup function to shared
cbosdo 92c7c29
Refactor kubernetes uninstall
cbosdo 6ae8f22
Merge kubernetes install/upgrade/migrate into one entry point
cbosdo bf0def5
Migration script improvements
cbosdo 5c44006
Change the --helm-* parameters into --kubernetes-*
cbosdo 1409477
Disable CGO build for Debian i586 to avoid cross-compiling
cbosdo 3a48af0
Handle traefik helm chart breaking change to expose ports
cbosdo 5d4058b
Run the first user creation from the setup script
cbosdo f65f29a
Remove the line end in the local timezone
cbosdo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,100 +7,17 @@ | |
package kubernetes | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/rs/zerolog" | ||
"github.com/rs/zerolog/log" | ||
"github.com/spf13/cobra" | ||
install_shared "github.com/uyuni-project/uyuni-tools/mgradm/cmd/install/shared" | ||
"github.com/uyuni-project/uyuni-tools/mgradm/shared/kubernetes" | ||
adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils" | ||
"github.com/uyuni-project/uyuni-tools/shared" | ||
shared_kubernetes "github.com/uyuni-project/uyuni-tools/shared/kubernetes" | ||
. "github.com/uyuni-project/uyuni-tools/shared/l10n" | ||
"github.com/uyuni-project/uyuni-tools/shared/types" | ||
shared_utils "github.com/uyuni-project/uyuni-tools/shared/utils" | ||
) | ||
|
||
func installForKubernetes(globalFlags *types.GlobalFlags, | ||
flags *kubernetesInstallFlags, | ||
func installForKubernetes( | ||
globalFlags *types.GlobalFlags, | ||
flags *kubernetes.KubernetesServerFlags, | ||
cmd *cobra.Command, | ||
args []string, | ||
) error { | ||
Comment on lines
+15
to
20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think for a clarity of code, as this is now just couple lines, can they be moved from Seems strange to me to have |
||
for _, binary := range []string{"kubectl", "helm"} { | ||
if _, err := exec.LookPath(binary); err != nil { | ||
return fmt.Errorf(L("install %s before running this command"), binary) | ||
} | ||
} | ||
|
||
flags.CheckParameters(cmd, "kubectl") | ||
cnx := shared.NewConnection("kubectl", "", shared_kubernetes.ServerFilter) | ||
|
||
fqdn := args[0] | ||
|
||
if err := shared_utils.IsValidFQDN(fqdn); err != nil { | ||
return err | ||
} | ||
|
||
helmArgs := []string{"--set", "timezone=" + flags.TZ} | ||
if flags.Mirror != "" { | ||
// TODO Handle claims for multi-node clusters | ||
helmArgs = append(helmArgs, "--set", "mirror.hostPath="+flags.Mirror) | ||
} | ||
if flags.Debug.Java { | ||
helmArgs = append(helmArgs, "--set", "exposeJavaDebug=true") | ||
} | ||
|
||
// Check the kubernetes cluster setup | ||
clusterInfos, err := shared_kubernetes.CheckCluster() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Deploy the SSL CA or server certificate | ||
ca := types.SSLPair{} | ||
sslArgs, err := kubernetes.DeployCertificate(&flags.Helm, &flags.SSL, "", &ca, clusterInfos.GetKubeconfig(), fqdn, | ||
flags.Image.PullPolicy) | ||
if err != nil { | ||
return shared_utils.Errorf(err, L("cannot deploy certificate")) | ||
} | ||
helmArgs = append(helmArgs, sslArgs...) | ||
|
||
// Create a secret using SCC credentials if any are provided | ||
helmArgs, err = shared_kubernetes.AddSCCSecret(helmArgs, flags.Helm.Uyuni.Namespace, &flags.SCC) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Deploy Uyuni and wait for it to be up | ||
if err := kubernetes.Deploy(cnx, flags.Image.Registry, &flags.Image, &flags.Helm, &flags.SSL, | ||
clusterInfos, fqdn, flags.Debug.Java, false, helmArgs..., | ||
); err != nil { | ||
return shared_utils.Errorf(err, L("cannot deploy uyuni")) | ||
} | ||
|
||
// Create setup script + env variables and copy it to the container | ||
envs := map[string]string{ | ||
"NO_SSL": "Y", | ||
} | ||
|
||
if err := install_shared.RunSetup(cnx, &flags.InstallFlags, args[0], envs); err != nil { | ||
namespace, err := cnx.GetNamespace("") | ||
if err != nil { | ||
return shared_utils.Errorf(err, L("failed to stop service")) | ||
} | ||
if stopErr := shared_kubernetes.Stop(namespace, shared_kubernetes.ServerApp); stopErr != nil { | ||
log.Error().Err(stopErr).Msg(L("failed to stop service")) | ||
} | ||
return err | ||
} | ||
|
||
// The CA needs to be added to the database for Kickstart use. | ||
err = adm_utils.ExecCommand(zerolog.DebugLevel, cnx, | ||
"/usr/bin/rhn-ssl-dbstore", "--ca-cert=/etc/pki/trust/anchors/LOCAL-RHN-ORG-TRUSTED-SSL-CERT") | ||
if err != nil { | ||
return shared_utils.Errorf(err, L("error storing the SSL CA certificate in database")) | ||
} | ||
return nil | ||
flags.Installation.CheckParameters(cmd, "kubectl") | ||
return kubernetes.Reconcile(flags, args[0]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A nitpick, probably due to various refactoring we keep this, but it is no longer needed, there is no namespace clash anymore.
Ofc the rest of the code will need to drop
shared_
prefix.This will also make it the same between inspect and install.