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

OCPVE-587: chore: update to k8s 1.27.x APIs and bump to go1.20 #371

Merged
merged 1 commit into from
Jul 27, 2023
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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