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

Cleanup BackupStorage api #14

Merged
merged 1 commit into from
Jan 11, 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ require (
k8s.io/klog/v2 v2.110.1
k8s.io/kubectl v0.29.0
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
kmodules.xyz/client-go v0.29.4
kmodules.xyz/client-go v0.29.6
kmodules.xyz/offshoot-api v0.29.0
kubestash.dev/apimachinery v0.3.1-0.20231231034418-cc46ddfd674a
kubestash.dev/apimachinery v0.3.1-0.20240111011911-c3c3817fcf7c
sigs.k8s.io/controller-runtime v0.16.3
)

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,16 @@ k8s.io/kubectl v0.29.0/go.mod h1:0jMjGWIcMIQzmUaMgAzhSELv5WtHo2a8pq67DtviAJs=
k8s.io/utils v0.0.0-20200729134348-d5654de09c73/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
kmodules.xyz/client-go v0.29.4 h1:WW4vlYtzLc9JXrJjcFuJO4DX/kIZ5ia7QtDyhNDUwfI=
kmodules.xyz/client-go v0.29.4/go.mod h1:xWlS/1zWkx1sIKCAkzULy9570mHZYi2exDECEoP1ek4=
kmodules.xyz/client-go v0.29.6 h1:xTVq5LZvsPBUTLY7PORq7zveLOj/vpuTDvkpHWOk3RM=
kmodules.xyz/client-go v0.29.6/go.mod h1:pHuzpwzEcDUIGjVVvwz9N8lY+6A7HXwvs2d7NtK7Hho=
kmodules.xyz/objectstore-api v0.29.0 h1:dK53fQXdoboyW/EyBBAMjykT8u7jstKrM1DS4RJvhEU=
kmodules.xyz/objectstore-api v0.29.0/go.mod h1:Kxmv6F7Kd/7EoKX3X2xIzhHT++zlj2qdXLcp/8avUYI=
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
kmodules.xyz/prober v0.29.0 h1:Ex7m4F9rH7uWNNJlLgP63ROOM+nUATJkC2L5OQ7nwMg=
kmodules.xyz/prober v0.29.0/go.mod h1:UtK+HKyI1lFLEKX+HFLyOCVju6TO93zv3kwGpzqmKOo=
kubestash.dev/apimachinery v0.3.1-0.20231231034418-cc46ddfd674a h1:zkRd7mpfFk2QtGKefGxZqpczy909KJCk4iPu9WOwCKU=
kubestash.dev/apimachinery v0.3.1-0.20231231034418-cc46ddfd674a/go.mod h1:ImhcNxJIdObtmm1jPeOnvK9TrwS7bXqNa8I4Um/Vf1A=
kubestash.dev/apimachinery v0.3.1-0.20240111011911-c3c3817fcf7c h1:Ec4XNFVWyq/cTOH7sOmLj1IBK8spyrJnUKPdxZuV2Jo=
kubestash.dev/apimachinery v0.3.1-0.20240111011911-c3c3817fcf7c/go.mod h1:mqOML23d9Hm2kSyzlRy6Gr69RGEUaOCTWYl2egklac8=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
Expand Down
54 changes: 28 additions & 26 deletions pkg/clone_pvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (opt *storageOption) getBackendInfo() storageapi.Backend {
Bucket: opt.bucket,
Prefix: opt.prefix,
MaxConnections: opt.maxConnections,
Secret: opt.storageSecret,
SecretName: opt.storageSecret,
},
}
case string(storageapi.ProviderAzure):
Expand All @@ -183,39 +183,41 @@ func (opt *storageOption) getBackendInfo() storageapi.Backend {
Container: opt.bucket,
Prefix: opt.prefix,
MaxConnections: opt.maxConnections,
Secret: opt.storageSecret,
SecretName: opt.storageSecret,
},
}
case string(storageapi.ProviderS3):
backend = storageapi.Backend{
Provider: storageapi.ProviderS3,
S3: &storageapi.S3Spec{
Bucket: opt.bucket,
Prefix: opt.prefix,
Endpoint: opt.endpoint,
Region: opt.region,
Secret: opt.storageSecret,
},
}
case string(storageapi.ProviderB2):
backend = storageapi.Backend{
Provider: storageapi.ProviderB2,
B2: &storageapi.B2Spec{
Bucket: opt.bucket,
Prefix: opt.prefix,
MaxConnections: opt.maxConnections,
Secret: opt.storageSecret,
},
}
case string(storageapi.ProviderSwift):
backend = storageapi.Backend{
Provider: storageapi.ProviderSwift,
Swift: &storageapi.SwiftSpec{
Container: opt.bucket,
Prefix: opt.prefix,
Secret: opt.storageSecret,
Bucket: opt.bucket,
Prefix: opt.prefix,
Endpoint: opt.endpoint,
Region: opt.region,
SecretName: opt.storageSecret,
},
}
/*
case string(storageapi.ProviderB2):
backend = storageapi.Backend{
Provider: storageapi.ProviderB2,
B2: &storageapi.B2Spec{
Bucket: opt.bucket,
Prefix: opt.prefix,
MaxConnections: opt.maxConnections,
Secret: opt.storageSecret,
},
}
case string(storageapi.ProviderSwift):
backend = storageapi.Backend{
Provider: storageapi.ProviderSwift,
Swift: &storageapi.SwiftSpec{
Container: opt.bucket,
Prefix: opt.prefix,
Secret: opt.storageSecret,
},
}
*/
}

return backend
Expand Down
87 changes: 87 additions & 0 deletions vendor/kmodules.xyz/client-go/apiextensions/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright AppsCode Inc. and Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package apiextensions

import (
"context"
"sync"

apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
)

type SetupFn func(ctx context.Context, mgr ctrl.Manager)

var setupFns = map[schema.GroupKind]SetupFn{
// schema.GroupKind{"compute.gcp.kubedb.com", "Firewall"}: firewall.Setup,
}

var (
setupDone = map[schema.GroupKind]bool{}
mu sync.Mutex
)

type Reconciler struct {
ctx context.Context
mgr ctrl.Manager
}

func NewReconciler(ctx context.Context, mgr ctrl.Manager) *Reconciler {
return &Reconciler{ctx: ctx, mgr: mgr}
}

func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)
var crd apiextensions.CustomResourceDefinition
if err := r.mgr.GetClient().Get(ctx, req.NamespacedName, &crd); err != nil {
log.Error(err, "unable to fetch CustomResourceDefinition")
return ctrl.Result{}, client.IgnoreNotFound(err)
}

gk := schema.GroupKind{
Group: crd.Spec.Group,
Kind: crd.Spec.Names.Kind,
}
mu.Lock()
defer mu.Unlock()
_, found := setupDone[gk]
if found {
return ctrl.Result{}, nil
}
setup, found := setupFns[gk]
if found {
setup(r.ctx, r.mgr)
setupDone[gk] = true
}
return ctrl.Result{}, nil
}

func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&apiextensions.CustomResourceDefinition{}).
Complete(r)
}

func RegisterSetup(gk schema.GroupKind, fn SetupFn) {
mu.Lock()
defer mu.Unlock()

setupFns[gk] = fn
}
20 changes: 20 additions & 0 deletions vendor/kmodules.xyz/client-go/apiextensions/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,23 @@ func WaitForCRDReady(client crd_cs.Interface, crds []*CustomResourceDefinition)
})
return errors.Wrap(err, "timed out waiting for CRD")
}

func RemoveCRDs(client crd_cs.Interface, crds []*CustomResourceDefinition) error {
for _, crd := range crds {
// Use crd v1 for k8s >= 1.16, if available
// ref: https://github.com/kubernetes/kubernetes/issues/91395
if crd.V1 == nil {
gvr := schema.GroupVersionResource{
Group: crd.V1beta1.Spec.Group,
Version: crd.V1beta1.Spec.Versions[0].Name,
Resource: crd.V1beta1.Spec.Names.Plural,
}
return fmt.Errorf("missing V1 definition for %s", gvr)
}
err := client.ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.V1.Name, metav1.DeleteOptions{})
if err != nil && !kerr.IsNotFound(err) {
return err
}
}
return nil
}
6 changes: 3 additions & 3 deletions vendor/kmodules.xyz/client-go/meta/preconditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

type PreConditionSet struct {
sets.String
sets.Set[string]
}

func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc {
Expand All @@ -36,7 +36,7 @@ func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc {
mergepatch.RequireMetadataKeyUnchanged("namespace"),
}

for _, field := range s.List() {
for _, field := range sets.List[string](s.Set) {
preconditions = append(preconditions,
RequireChainKeyUnchanged(field),
)
Expand All @@ -45,7 +45,7 @@ func (s PreConditionSet) PreconditionFunc() []mergepatch.PreconditionFunc {
}

func (s PreConditionSet) Error() error {
strList := strings.Join(s.List(), "\n\t")
strList := strings.Join(sets.List[string](s.Set), "\n\t")
return fmt.Errorf(strings.Join([]string{`At least one of the following was changed:
apiVersion
kind
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/kubestash.dev/apimachinery/apis/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ const (
)

const (
ComponentPod = "pod"
ComponentDeployment = "deployment"
ComponentPVC = "pvc"
ComponentDump = "dump"
ComponentWal = "wal"
ComponentManifests = "manifests"
ComponentVolumeSnapshots = "volumesnapshots"
ComponentPod = "pod"
ComponentDeployment = "deployment"
ComponentPVC = "pvc"
ComponentDump = "dump"
ComponentWal = "wal"
ComponentManifest = "manifest"
ComponentVolumeSnapshot = "volumesnapshot"
)

const (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,19 @@ func (r *BackupStorage) isPointToSameDir(bs BackupStorage) bool {
return true
}
return false
case ProviderB2:
if r.Spec.Storage.B2.Bucket == bs.Spec.Storage.B2.Bucket &&
r.Spec.Storage.B2.Prefix == bs.Spec.Storage.B2.Prefix {
return true
}
return false
case ProviderSwift:
// TODO: check for account
if r.Spec.Storage.Swift.Container == bs.Spec.Storage.Swift.Container &&
r.Spec.Storage.Swift.Prefix == bs.Spec.Storage.Swift.Prefix {
return true
}
return false
//case ProviderB2:
// if r.Spec.Storage.B2.Bucket == bs.Spec.Storage.B2.Bucket &&
// r.Spec.Storage.B2.Prefix == bs.Spec.Storage.B2.Prefix {
// return true
// }
// return false
//case ProviderSwift:
// // TODO: check for account
// if r.Spec.Storage.Swift.Container == bs.Spec.Storage.Swift.Container &&
// r.Spec.Storage.Swift.Prefix == bs.Spec.Storage.Swift.Prefix {
// return true
// }
// return false
default:
return false
}
Expand Down
Loading
Loading