Skip to content

Commit

Permalink
chore: update to k8s 1.27.x APIs and bump to go1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev committed Jul 27, 2023
1 parent 255d754 commit 3ca4bf6
Show file tree
Hide file tree
Showing 830 changed files with 68,093 additions and 30,127 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM golang:1.20 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
51 changes: 26 additions & 25 deletions api/v1alpha1/lvmcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -45,69 +46,69 @@ func (l *LVMCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (l *LVMCluster) ValidateCreate() error {
func (l *LVMCluster) ValidateCreate() (admission.Warnings, error) {
lvmclusterlog.Info("validate create", "name", l.Name)

err := l.verifySingleDefaultDeviceClass()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyPathsAreNotEmpty()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyAbsolutePath()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyNoDeviceOverlap()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyFstype()
if err != nil {
return err
return admission.Warnings{}, err
}

return nil
return admission.Warnings{}, nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (l *LVMCluster) ValidateUpdate(old runtime.Object) error {
func (l *LVMCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
lvmclusterlog.Info("validate update", "name", l.Name)

err := l.verifySingleDefaultDeviceClass()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyPathsAreNotEmpty()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyAbsolutePath()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyNoDeviceOverlap()
if err != nil {
return err
return admission.Warnings{}, err
}

err = l.verifyFstype()
if err != nil {
return err
return admission.Warnings{}, err
}

oldLVMCluster, ok := old.(*LVMCluster)
if !ok {
return fmt.Errorf("Failed to parse LVMCluster.")
return admission.Warnings{}, fmt.Errorf("Failed to parse LVMCluster.")
}

for _, deviceClass := range l.Spec.Storage.DeviceClasses {
Expand All @@ -119,16 +120,16 @@ func (l *LVMCluster) ValidateUpdate(old runtime.Object) error {

if (newThinPoolConfig != nil && oldThinPoolConfig == nil && err != ErrDeviceClassNotFound) ||
(newThinPoolConfig == nil && oldThinPoolConfig != nil) {
return fmt.Errorf("ThinPoolConfig can not be changed")
return admission.Warnings{}, fmt.Errorf("ThinPoolConfig can not be changed")
}

if newThinPoolConfig != nil && oldThinPoolConfig != nil {
if newThinPoolConfig.Name != oldThinPoolConfig.Name {
return fmt.Errorf("ThinPoolConfig.Name can not be changed")
return admission.Warnings{}, fmt.Errorf("ThinPoolConfig.Name can not be changed")
} else if newThinPoolConfig.SizePercent != oldThinPoolConfig.SizePercent {
return fmt.Errorf("ThinPoolConfig.SizePercent can not be changed")
return admission.Warnings{}, fmt.Errorf("ThinPoolConfig.SizePercent can not be changed")
} else if newThinPoolConfig.OverprovisionRatio != oldThinPoolConfig.OverprovisionRatio {
return fmt.Errorf("ThinPoolConfig.OverprovisionRatio can not be changed")
return admission.Warnings{}, fmt.Errorf("ThinPoolConfig.OverprovisionRatio can not be changed")
}
}

Expand All @@ -146,28 +147,28 @@ func (l *LVMCluster) ValidateUpdate(old runtime.Object) error {

// Make sure a device path list was not added
if len(oldDevices) == 0 && len(newDevices) > 0 {
return fmt.Errorf("invalid: device paths can not be added after a device class has been initialized")
return admission.Warnings{}, fmt.Errorf("invalid: device paths can not be added after a device class has been initialized")
}

// Make sure an optionalPaths list was not added
if len(oldOptionalDevices) == 0 && len(newOptionalDevices) > 0 {
return fmt.Errorf("invalid: optional device paths can not be added after a device class has been initialized")
return admission.Warnings{}, fmt.Errorf("invalid: optional device paths can not be added after a device class has been initialized")
}

// Validate all the old paths still exist
err := validateDevicePathsStillExist(oldDevices, newDevices)
if err != nil {
return fmt.Errorf("invalid: required device paths were deleted from the LVMCluster: %v", err)
return admission.Warnings{}, fmt.Errorf("invalid: required device paths were deleted from the LVMCluster: %v", err)
}

// Validate all the old optional paths still exist
err = validateDevicePathsStillExist(oldOptionalDevices, newOptionalDevices)
if err != nil {
return fmt.Errorf("invalid: optional device paths were deleted from the LVMCluster: %v", err)
return admission.Warnings{}, fmt.Errorf("invalid: optional device paths were deleted from the LVMCluster: %v", err)
}
}

return nil
return admission.Warnings{}, nil
}

func validateDevicePathsStillExist(old, new []string) error {
Expand All @@ -190,10 +191,10 @@ func validateDevicePathsStillExist(old, new []string) error {
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (l *LVMCluster) ValidateDelete() error {
func (l *LVMCluster) ValidateDelete() (admission.Warnings, error) {
lvmclusterlog.Info("validate delete", "name", l.Name)

return nil
return []string{}, nil
}

func (l *LVMCluster) verifySingleDefaultDeviceClass() error {
Expand Down
9 changes: 4 additions & 5 deletions controllers/lvmcluster_controller_watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// SetupWithManager sets up the controller with the Manager.
Expand All @@ -38,23 +37,23 @@ func (r *LVMClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&lvmv1alpha1.LVMVolumeGroup{}).
Owns(&lvmv1alpha1.LVMVolumeGroupNodeStatus{}).
Watches(
&source.Kind{Type: &lvmv1alpha1.LVMVolumeGroupNodeStatus{}},
&lvmv1alpha1.LVMVolumeGroupNodeStatus{},
handler.EnqueueRequestsFromMapFunc(r.getLVMClusterObjsForReconcile),
).
Watches(
&source.Kind{Type: &storagev1.StorageClass{}},
&storagev1.StorageClass{},
handler.EnqueueRequestsFromMapFunc(r.getLVMClusterObjsForReconcile),
).
Complete(r)
}

func (r *LVMClusterReconciler) getLVMClusterObjsForReconcile(obj client.Object) []reconcile.Request {
func (r *LVMClusterReconciler) getLVMClusterObjsForReconcile(ctx context.Context, obj client.Object) []reconcile.Request {
foundLVMClusterList := &lvmv1alpha1.LVMClusterList{}
listOps := &client.ListOptions{
Namespace: obj.GetNamespace(),
}

err := r.Client.List(context.TODO(), foundLVMClusterList, listOps)
err := r.Client.List(ctx, foundLVMClusterList, listOps)
if err != nil {
r.Log.Error(err, "getLVMClusterObjsForReconcile: Failed to get LVMCluster objs")
return []reconcile.Request{}
Expand Down
2 changes: 1 addition & 1 deletion controllers/persistent-volume-claim/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestPersistentVolumeClaimReconciler_Reconcile(t *testing.T) {
objs: []client.Object{
&v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{Namespace: defaultNamespace, Name: "test-deletionTimestamp",
DeletionTimestamp: &metav1.Time{Time: time.Now()}},
DeletionTimestamp: &metav1.Time{Time: time.Now()}, Finalizers: []string{"random-finalizer"}},
},
},
},
Expand Down
81 changes: 40 additions & 41 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
module github.com/openshift/lvm-operator

go 1.18
go 1.20

require (
github.com/aws/aws-sdk-go v1.44.10
github.com/go-logr/logr v1.2.4
github.com/google/go-cmp v0.5.9
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/onsi/ginkgo/v2 v2.9.4
github.com/onsi/gomega v1.27.6
github.com/openshift/api v0.0.0-20211028023115-7224b732cc14
github.com/openshift/client-go v0.0.0-20210831095141-e19a065e79f7
github.com/onsi/ginkgo/v2 v2.9.5
github.com/onsi/gomega v1.27.7
github.com/openshift/api v0.0.0-20230613151523-ba04973d3ed1
github.com/openshift/client-go v0.0.0-20230503144108-75015d2347cb
github.com/openshift/custom-resource-status v1.1.2
github.com/operator-framework/api v0.17.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/stretchr/testify v1.8.0
github.com/prometheus/client_golang v1.16.0
github.com/stretchr/testify v1.8.4
github.com/topolvm/topolvm v0.15.4-0.20221116041433-d58476400ff1
gotest.tools/v3 v3.0.3
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/component-helpers v0.23.4
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448
sigs.k8s.io/controller-runtime v0.14.6
k8s.io/api v0.27.4
k8s.io/apimachinery v0.27.4
k8s.io/client-go v0.27.4
k8s.io/component-helpers v0.27.4
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
sigs.k8s.io/controller-runtime v0.15.0
sigs.k8s.io/yaml v1.3.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cybozu-go/log v1.6.0 // indirect
github.com/cybozu-go/netutil v1.2.0 // indirect
github.com/cybozu-go/well v1.10.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand All @@ -53,55 +53,54 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.6.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.10.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.8.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
golang.org/x/tools v0.9.1 // indirect
gomodules.xyz/jsonpatch/v2 v2.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/component-base v0.26.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
k8s.io/apiextensions-apiserver v0.27.2 // indirect
k8s.io/component-base v0.27.2 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)
Loading

0 comments on commit 3ca4bf6

Please sign in to comment.