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

Bump Go versions #494

Merged
merged 3 commits into from
Dec 4, 2024
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
516 changes: 285 additions & 231 deletions go.mod

Large diffs are not rendered by default.

2,022 changes: 637 additions & 1,385 deletions go.sum

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions internal/civo/objectStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,23 @@ var errNoCredsFound = errors.New("no object store credentials found")
// checkKubefirstCredentials determines whether or not object store credentials exist
func (c *Configuration) checkKubefirstCredentials(credentialName string) (*civogo.ObjectStoreCredential, error) {
log.Info().Msgf("looking for credential: %s", credentialName)
remoteCredentials, err := c.Client.ListObjectStoreCredentials()
if err != nil {
log.Error().Msg(err.Error())
return nil, fmt.Errorf("error fetching object store credentials: %w", err)
}

for i, cred := range remoteCredentials.Items {
if cred.Name == credentialName {
log.Info().Msgf("found credential: %s", credentialName)
return &remoteCredentials.Items[i], nil
for page := 1; ; page++ {
remoteCredentials, err := c.Client.ListObjectStoreCredentials(page, 100)
if err != nil {
log.Error().Msg(err.Error())
return nil, fmt.Errorf("error fetching object store credentials: %w", err)
}

if len(remoteCredentials.Items) == 0 || remoteCredentials.Pages == page {
break
}

for _, credential := range remoteCredentials.Items {
if credential.Name == credentialName {
log.Info().Msgf("found credential: %s", credentialName)
return &credential, nil
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"context"
"fmt"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/rs/zerolog/log"
)
Expand All @@ -26,7 +26,7 @@ func NewDockerClient() *client.Client {
}

func (docker ClientWrapper) ListContainers() {
containers, err := docker.Client.ContainerList(context.Background(), types.ContainerListOptions{})
containers, err := docker.Client.ContainerList(context.Background(), container.ListOptions{})
if err != nil {
log.Error().Msg(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (gl *Wrapper) DeleteUserSSHKey(keyTitle string) error {

// GetUserSSHKeys
func (gl *Wrapper) GetUserSSHKeys() ([]*gitlab.SSHKey, error) {
keys, _, err := gl.Client.Users.ListSSHKeys()
keys, _, err := gl.Client.Users.ListSSHKeys(nil)
if err != nil {
return nil, fmt.Errorf("could not get user ssh keys: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/k3d/adjustContent.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func AdjustGitopsRepo(cloudProvider, clusterName, clusterType, gitopsRepoDir, gi

// * copy options
opt := cp.Options{
Skip: func(src string) (bool, error) {
Skip: func(_ os.FileInfo, src, _ string) (bool, error) {
if strings.HasSuffix(src, ".git") || strings.Index(src, "/.terraform") > 0 {
return true, nil
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func AdjustMetaphorRepo(destinationMetaphorRepoGitURL, gitopsRepoDir, gitProvide

// * copy options
opt := cp.Options{
Skip: func(src string) (bool, error) {
Skip: func(_ os.FileInfo, src, _ string) (bool, error) {
if strings.HasSuffix(src, ".git") {
return true, nil
} else if strings.Index(src, "/.terraform") > 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/k8s/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
memory "k8s.io/client-go/discovery/cached"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/restmapper"
kbuild "sigs.k8s.io/kustomize/kustomize/v4/commands/build"
kbuild "sigs.k8s.io/kustomize/kustomize/v5/commands/build"
"sigs.k8s.io/kustomize/kyaml/filesys"
)

Expand Down
103 changes: 13 additions & 90 deletions internal/k8s/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ import (
"context"
"errors"
"fmt"
"io"
"net"
"os"
"syscall"
"time"

"github.com/rs/zerolog/log"
"golang.org/x/term"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/remotecommand"
)

// CreateSecretV2 creates a Kubernetes Secret
Expand Down Expand Up @@ -92,84 +87,12 @@ func ReadService(kubeConfigPath, namespace, serviceName string) (*v1.Service, er
return service, nil
}

// PodExecSession executes a command against a Pod
func PodExecSession(kubeConfigPath string, p *PodSessionOptions, silent bool) error {
// v1.PodExecOptions is passed to the rest client to form the req URL
podExecOptions := v1.PodExecOptions{
Stdin: p.Stdin,
Stdout: p.Stdout,
Stderr: p.Stderr,
TTY: p.TtyEnabled,
Command: p.Command,
}

err := podExec(kubeConfigPath, p, podExecOptions, silent)
if err != nil {
return fmt.Errorf("error executing command in Pod %q: %w", p.PodName, err)
}
return nil
}

// podExec performs kube-exec on a Pod with a given command
func podExec(kubeConfigPath string, ps *PodSessionOptions, pe v1.PodExecOptions, silent bool) error {
clientset, err := GetClientSet(kubeConfigPath)
if err != nil {
return fmt.Errorf("error getting client set from kubeConfigPath %q: %w", kubeConfigPath, err)
}

config, err := GetClientConfig(kubeConfigPath)
if err != nil {
return fmt.Errorf("error getting client config from kubeConfigPath %q: %w", kubeConfigPath, err)
}

// Format the request to be sent to the API
req := clientset.CoreV1().RESTClient().Post().
Resource("pods").
Name(ps.PodName).
Namespace(ps.Namespace).
SubResource("exec")
req.VersionedParams(&pe, scheme.ParameterCodec)

// POST op against Kubernetes API to initiate remote command
exec, err := remotecommand.NewSPDYExecutor(config, "POST", req.URL())
if err != nil {
log.Error().Msgf("error executing command on Pod %s in Namespace %s: %s", ps.PodName, ps.Namespace, err)
return fmt.Errorf("error executing command on Pod %q in Namespace %q: %w", ps.PodName, ps.Namespace, err)
}

// Put the terminal into raw mode to prevent it echoing characters twice
oldState, err := term.MakeRaw(0)
if err != nil {
log.Error().Msgf("error when attempting to start terminal: %s", err)
return fmt.Errorf("error when attempting to start terminal: %w", err)
}
defer term.Restore(0, oldState)

var showOutput io.Writer
if silent {
showOutput = io.Discard
} else {
showOutput = os.Stdout
}
err = exec.Stream(remotecommand.StreamOptions{
Stdin: os.Stdin,
Stdout: showOutput,
Stderr: os.Stderr,
Tty: ps.TtyEnabled,
})
if err != nil {
log.Error().Msgf("error streaming pod command in Pod %s: %s", ps.PodName, err)
return fmt.Errorf("error streaming pod command in Pod %q: %w", ps.PodName, err)
}
return nil
}

func ReturnDeploymentObject(client kubernetes.Interface, matchLabel string, matchLabelValue string, namespace string, timeoutSeconds int) (*appsv1.Deployment, error) {
timeout := time.Duration(timeoutSeconds) * time.Second
var deployment *appsv1.Deployment

err := wait.PollImmediate(15*time.Second, timeout, func() (bool, error) {
deployments, err := client.AppsV1().Deployments(namespace).List(context.Background(), metav1.ListOptions{
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, timeout, true, func(ctx context.Context) (bool, error) {
deployments, err := client.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", matchLabel, matchLabelValue),
})
if err != nil {
Expand Down Expand Up @@ -217,8 +140,8 @@ func ReturnPodObject(kubeConfigPath, matchLabel, matchLabelValue, namespace stri

var pod *v1.Pod

err = wait.PollImmediate(5*time.Second, time.Duration(timeoutSeconds)*time.Second, func() (bool, error) {
podList, err := clientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{
err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, time.Duration(timeoutSeconds)*time.Second, true, func(ctx context.Context) (bool, error) {
podList, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
LabelSelector: labelSelector,
})
if err != nil {
Expand Down Expand Up @@ -262,8 +185,8 @@ func ReturnStatefulSetObject(clientset kubernetes.Interface, matchLabel, matchLa

var statefulSet *appsv1.StatefulSet

err := wait.PollImmediate(5*time.Second, time.Duration(timeoutSeconds)*time.Second, func() (bool, error) {
statefulSets, err := clientset.AppsV1().StatefulSets(namespace).List(context.Background(), metav1.ListOptions{
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, time.Duration(timeoutSeconds)*time.Second, true, func(ctx context.Context) (bool, error) {
statefulSets, err := clientset.AppsV1().StatefulSets(namespace).List(ctx, metav1.ListOptions{
LabelSelector: labelSelector,
})
if err != nil {
Expand Down Expand Up @@ -314,9 +237,9 @@ func WaitForDeploymentReady(clientset kubernetes.Interface, deployment *appsv1.D

log.Info().Msgf("waiting for deployment %q in namespace %q to be ready - this could take up to %v seconds", deploymentName, namespace, timeoutSeconds)

err := wait.PollImmediate(5*time.Second, time.Duration(timeoutSeconds)*time.Second, func() (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, time.Duration(timeoutSeconds)*time.Second, true, func(ctx context.Context) (bool, error) {
// Get the latest Deployment object
currentDeployment, err := clientset.AppsV1().Deployments(namespace).Get(context.Background(), deploymentName, metav1.GetOptions{})
currentDeployment, err := clientset.AppsV1().Deployments(namespace).Get(ctx, deploymentName, metav1.GetOptions{})
if err != nil {
// If we couldn't connect, retry
if isNetworkingError(err) {
Expand Down Expand Up @@ -352,9 +275,9 @@ func WaitForPodReady(clientset kubernetes.Interface, pod *v1.Pod, timeoutSeconds

log.Info().Msgf("waiting for pod %q in namespace %q to be ready - this could take up to %v seconds", podName, namespace, timeoutSeconds)

err := wait.PollImmediate(5*time.Second, time.Duration(timeoutSeconds)*time.Second, func() (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, time.Duration(timeoutSeconds)*time.Second, true, func(ctx context.Context) (bool, error) {
// Get the latest Pod object
currentPod, err := clientset.CoreV1().Pods(namespace).Get(context.Background(), podName, metav1.GetOptions{})
currentPod, err := clientset.CoreV1().Pods(namespace).Get(ctx, podName, metav1.GetOptions{})
if err != nil {
// If we couldn't connect, retry
if isNetworkingError(err) {
Expand Down Expand Up @@ -397,9 +320,9 @@ func WaitForStatefulSetReady(clientset kubernetes.Interface, statefulset *appsv1

log.Info().Msgf("waiting for statefulset %q in namespace %q to be ready - this could take up to %v seconds", statefulSetName, namespace, timeoutSeconds)

err := wait.PollImmediate(5*time.Second, time.Duration(timeoutSeconds)*time.Second, func() (bool, error) {
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, time.Duration(timeoutSeconds)*time.Second, true, func(ctx context.Context) (bool, error) {
// Get the latest StatefulSet object
currentStatefulSet, err := clientset.AppsV1().StatefulSets(namespace).Get(context.Background(), statefulSetName, metav1.GetOptions{})
currentStatefulSet, err := clientset.AppsV1().StatefulSets(namespace).Get(ctx, statefulSetName, metav1.GetOptions{})
if err != nil {
// If we couldn't connect, retry
if isNetworkingError(err) {
Expand All @@ -418,7 +341,7 @@ func WaitForStatefulSetReady(clientset kubernetes.Interface, statefulset *appsv1
currentRevision := currentStatefulSet.Status.CurrentRevision

// Get Pods owned by the StatefulSet
pods, err := clientset.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{
pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
LabelSelector: fmt.Sprintf("controller-revision-hash=%s", currentRevision),
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/progressPrinter/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func SetupProgress(numTrackers int, silentMode bool) {

instance.pw.SetAutoStop(false)
instance.pw.SetTrackerLength(40)
instance.pw.SetMessageWidth(39)
instance.pw.SetMessageLength(39)
instance.pw.SetNumTrackersExpected(numTrackers)
instance.pw.SetSortBy(progress.SortByPercentDsc)
instance.pw.SetStyle(progress.StyleDefault)
Expand Down
2 changes: 1 addition & 1 deletion internal/progress_bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func SetupProgress(numTrackers int) {
pw = progress.NewWriter()
pw.SetAutoStop(false)
pw.SetTrackerLength(40)
pw.SetMessageWidth(39)
pw.SetMessageLength(39)
pw.SetNumTrackersExpected(numTrackers)
pw.SetSortBy(progress.SortByPercentDsc)
pw.SetStyle(progress.StyleDefault)
Expand Down
5 changes: 3 additions & 2 deletions pkg/providerConfigs/adjustDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package providerConfigs //nolint:revive,stylecheck // allowing temporarily for b

import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -50,7 +51,7 @@ func removeAllWithLogger(path string) {

func adjustGitOpsRepoForProvider(cloudProvider, gitProvider, gitopsRepoDir, clusterType, clusterName string, apexContentExists, isK3D bool) error {
opt := cp.Options{
Skip: func(src string) (bool, error) {
Skip: func(_ fs.FileInfo, src string, _ string) (bool, error) {
if strings.HasSuffix(src, ".git") {
return true, nil
} else if strings.Index(src, "/.terraform") > 0 {
Expand Down Expand Up @@ -191,7 +192,7 @@ func AdjustGitopsRepo(

func copyContents(source, destination string, createPath bool) error {
opt := cp.Options{
Skip: func(src string) (bool, error) {
Skip: func(_ fs.FileInfo, src string, _ string) (bool, error) {
if strings.HasSuffix(src, ".git") {
return true, nil
} else if strings.Index(src, "/.terraform") > 0 {
Expand Down
Loading