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

chore(velero): bump velero client to latest 1.15.0 #5066

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 4 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.0
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,10 +418,10 @@ 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/onsi/ginkgo v1.11.0 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
Expand Down Expand Up @@ -457,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
49 changes: 9 additions & 40 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all the velero object interactions now rely on:

  • func GetKubeClient(ctx context.Context) (kbclient.WithWatch, 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")
    }
    kcli, err := kbclient.NewWithWatch(cfg, kbclient.Options{})
    if err != nil {
    return nil, errors.Wrap(err, "failed to create kubebuilder client")
    }
    return kcli, nil
    }

Which has the scheme set via:

  • func init() {
    kubernetesConfigFlags = genericclioptions.NewConfigFlags(false)
    embeddedclusterv1beta1.AddToScheme(scheme.Scheme)
    velerov1.AddToScheme(scheme.Scheme)
    }

We probably don't need this anymore. Nevertheless keeping it for now just be cautious. Once we refactor our client usage across the board and drop a lof of our clientset usages we can take care of removing these.

}

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{})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the watch interface for our informer:

  • backupWatch, err := veleroClient.Watch(context.TODO(), &backupList, kbclient.InNamespace(veleroNamespace), &kbclient.ListOptions{
    Raw: &metav1.ListOptions{ResourceVersion: "0"},
    })

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
Loading