Skip to content

Commit

Permalink
chore(velero): bump velero client to latest 1.15.0 (#5066)
Browse files Browse the repository at this point in the history
* chore(velero): bump velero client to latest 1.15.0

* chore: should be building now

* chore: timestamp tests are driving me nuts

* chore: fixup more tests

* chore: make k8sutil use a single client

* bump test k8s version

* return k8s version

* compile with velero 1.12 to isolate error

* try with velero 1.14 just to make sure

* .1

* revert change to location of install scripts in ttl.sh image

* Revert "revert change to location of install scripts in ttl.sh image"

This reverts commit 1904a37.

* list podvolumerestores within the velero namespace only for rbac reasons

* go mod tidy

* remove confusing unreachable code

* unshadow variables

* further clarify

* update error message

* go mod tidy

---------

Co-authored-by: Andrew Lavery <[email protected]>
  • Loading branch information
JGAntunes and laverya authored Jan 6, 2025
1 parent 14f66f1 commit bfac515
Show file tree
Hide file tree
Showing 25 changed files with 385 additions and 596 deletions.
11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.10.0
github.com/tj/go-spin v1.1.0
github.com/vmware-tanzu/velero v1.14.1
github.com/vmware-tanzu/velero v1.15.1
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.31.0
Expand Down Expand Up @@ -398,6 +398,7 @@ require (
cloud.google.com/go/auth v0.9.8 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.4 // indirect
cloud.google.com/go/monitoring v1.21.1 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.24.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.48.1 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
Expand All @@ -417,8 +418,7 @@ require (
github.com/go-viper/mapstructure/v2 v2.1.0 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/kopia/kopia v0.10.7 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0 // indirect
github.com/kubernetes-csi/external-snapshotter/client/v7 v7.0.0 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/otiai10/mint v1.6.3 // indirect
Expand Down Expand Up @@ -458,8 +458,3 @@ replace (
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce => github.com/dmacvicar/golang-x-crypto v0.0.0-20220126233154-a96af8f07497
gopkg.in/square/go-jose.v2 => gopkg.in/square/go-jose.v2 v2.2.2
)

// This is the only way I could get these two to play nice together
// When getting github.com/replicatedhq/[email protected] or later, it pulls in github.com/replicatedhq/[email protected] which fails with the following error:
// ../../../../pkg/mod/github.com/vmware-tanzu/[email protected]/pkg/builder/persistent_volume_claim_builder.go:104:32: cannot use dataSourceRef (variable of type *"k8s.io/api/core/v1".TypedLocalObjectReference) as *"k8s.io/api/core/v1".TypedObjectReference value in assignment
replace github.com/vmware-tanzu/velero => github.com/vmware-tanzu/velero v1.10.3
50 changes: 9 additions & 41 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pkg/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
kotsscheme "github.com/replicatedhq/kotskinds/client/kotsclientset/scheme"
troubleshootscheme "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/scheme"
yaml "github.com/replicatedhq/yaml/v3"
veleroscheme "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/scheme"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"k8s.io/client-go/kubernetes/scheme"
)

Expand All @@ -35,7 +35,7 @@ func NewHandler() *Handler {
func init() {
kotsscheme.AddToScheme(scheme.Scheme)
troubleshootscheme.AddToScheme(scheme.Scheme)
veleroscheme.AddToScheme(scheme.Scheme)
velerov1.AddToScheme(scheme.Scheme)
}

func RegisterSessionAuthRoutes(r *mux.Router, kotsStore store.Store, handler KOTSHandler, middleware *policy.Middleware) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/handlers/snapshot_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
kotssnapshot "github.com/replicatedhq/kots/pkg/snapshot"
"github.com/replicatedhq/kots/pkg/util"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
veleroclientv1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
"k8s.io/client-go/kubernetes"
)

Expand All @@ -35,9 +34,9 @@ func (h *Handler) DownloadSnapshotLogs(w http.ResponseWriter, r *http.Request) {
return
}

veleroClient, err := veleroclientv1.NewForConfig(cfg)
veleroClient, err := k8sutil.GetKubeClient(r.Context())
if err != nil {
err = errors.Wrap(err, "failed to create velero clientset")
err = errors.Wrap(err, "failed to create velero client")
logger.Error(err)
w.WriteHeader(http.StatusInternalServerError)
return
Expand Down
24 changes: 11 additions & 13 deletions pkg/informers/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"github.com/replicatedhq/kots/pkg/supportbundle"
"github.com/replicatedhq/kots/pkg/util"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
veleroclientv1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/kubernetes"
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
)

// Start will start the kots informers
Expand All @@ -39,12 +39,15 @@ func Start() error {
return errors.Wrap(err, "failed to detect velero namespace")
}

veleroClient, err := veleroclientv1.NewForConfig(cfg)
veleroClient, err := k8sutil.GetKubeClient(context.TODO())
if err != nil {
return errors.Wrap(err, "failed to create velero clientset")
return errors.Wrap(err, "failed to create velero client")
}

backupWatch, err := veleroClient.Backups(veleroNamespace).Watch(context.TODO(), metav1.ListOptions{ResourceVersion: "0"})
var backupList velerov1.BackupList
backupWatch, err := veleroClient.Watch(context.TODO(), &backupList, kbclient.InNamespace(veleroNamespace), &kbclient.ListOptions{
Raw: &metav1.ListOptions{ResourceVersion: "0"},
})
if err != nil {
if kuberneteserrors.IsNotFound(err) {
return nil
Expand Down Expand Up @@ -86,7 +89,8 @@ func Start() error {

backup.Annotations["kots.io/support-bundle-requested"] = time.Now().UTC().Format(time.RFC3339)

if _, err := veleroClient.Backups(backup.Namespace).Update(context.TODO(), backup, metav1.UpdateOptions{}); err != nil {
var backup velerov1.Backup
if err := veleroClient.Update(context.TODO(), &backup); err != nil {
logger.Error(err)
continue
}
Expand All @@ -97,14 +101,8 @@ func Start() error {
continue
}

updatedBackup, err := veleroClient.Backups(backup.Namespace).Get(context.TODO(), backup.Name, metav1.GetOptions{})
if err != nil {
logger.Error(err)
continue
}

updatedBackup.Annotations["kots.io/support-bundle-id"] = supportBundleID
if _, err := veleroClient.Backups(backup.Namespace).Update(context.TODO(), updatedBackup, metav1.UpdateOptions{}); err != nil {
backup.Annotations["kots.io/support-bundle-id"] = supportBundleID
if err := veleroClient.Update(context.TODO(), &backup); err != nil {
logger.Error(err)
continue
}
Expand Down
26 changes: 3 additions & 23 deletions pkg/k8sutil/clientset.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
flag "github.com/spf13/pflag"
velerov1 "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/discovery"
Expand All @@ -37,6 +36,7 @@ var kubernetesConfigFlags *genericclioptions.ConfigFlags
func init() {
kubernetesConfigFlags = genericclioptions.NewConfigFlags(false)
embeddedclusterv1beta1.AddToScheme(scheme.Scheme)
velerov1.AddToScheme(scheme.Scheme)
}

func AddFlags(flags *flag.FlagSet) {
Expand Down Expand Up @@ -154,7 +154,7 @@ func GetDynamicResourceInterface(gvk *schema.GroupVersionKind, namespace string)
return dr, nil
}

func GetKubeClient(ctx context.Context) (kbclient.Client, error) {
func GetKubeClient(ctx context.Context) (kbclient.WithWatch, error) {
k8slogger := zap.New(func(o *zap.Options) {
o.DestWriter = io.Discard
})
Expand All @@ -163,27 +163,7 @@ func GetKubeClient(ctx context.Context) (kbclient.Client, error) {
if err != nil {
return nil, errors.Wrap(err, "failed to get cluster config")
}
kcli, err := kbclient.New(cfg, kbclient.Options{})
if err != nil {
return nil, errors.Wrap(err, "failed to create kubebuilder client")
}
return kcli, nil
}

func GetVeleroKubeClient(ctx context.Context) (kbclient.Client, error) {
k8slogger := zap.New(func(o *zap.Options) {
o.DestWriter = io.Discard
})
log.SetLogger(k8slogger)
cfg, err := GetClusterConfig()
if err != nil {
return nil, errors.Wrap(err, "failed to get cluster config")
}
scheme := runtime.NewScheme()
velerov1.AddToScheme(scheme)
kcli, err := kbclient.New(cfg, kbclient.Options{
Scheme: scheme,
})
kcli, err := kbclient.NewWithWatch(cfg, kbclient.Options{})
if err != nil {
return nil, errors.Wrap(err, "failed to create kubebuilder client")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/kotsadm/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/replicatedhq/kots/pkg/logger"
"github.com/replicatedhq/kots/pkg/snapshot"
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
veleroclientv1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
corev1 "k8s.io/api/core/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand Down Expand Up @@ -193,9 +192,9 @@ func MigrateExistingMinioFilesystemDeployments(log *logger.CLILogger, deployOpti
return errors.Wrap(err, "failed to create clientset")
}

veleroClient, err := veleroclientv1.NewForConfig(cfg)
veleroClient, err := k8sutil.GetKubeClient(context.TODO())
if err != nil {
return errors.Wrap(err, "failed to create velero clientset")
return errors.Wrap(err, "failed to create velero client")
}

bsl, err := snapshot.FindBackupStoreLocation(context.TODO(), clientset, veleroClient, deployOptions.Namespace)
Expand Down
Loading

0 comments on commit bfac515

Please sign in to comment.