Skip to content

Commit 6862e1e

Browse files
committed
remove extra obj region validation that is incompatible with newer regions
(cherry picked from commit dc679e5)
1 parent 9013d31 commit 6862e1e

File tree

3 files changed

+2
-48
lines changed

3 files changed

+2
-48
lines changed

internal/webhook/v1alpha2/linodeobjectstoragebucket_webhook.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"slices"
2323

24+
"github.com/linode/linodego"
2425
apierrors "k8s.io/apimachinery/pkg/api/errors"
2526
"k8s.io/apimachinery/pkg/runtime"
2627
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -109,7 +110,7 @@ func (v *LinodeObjectStorageBucketCustomValidator) validateLinodeObjectStorageBu
109110
if skipAPIValidation {
110111
return errs
111112
}
112-
if err := validateObjectStorageRegion(ctx, linodeClient, bucket.Spec.Region, field.NewPath("spec").Child("region")); err != nil {
113+
if err := validateRegion(ctx, linodeClient, bucket.Spec.Region, field.NewPath("spec").Child("region"), linodego.CapabilityObjectStorage); err != nil {
113114
errs = append(errs, err)
114115
}
115116

internal/webhook/v1alpha2/linodeobjectstoragebucket_webhook_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,6 @@ func TestValidateLinodeObjectStorageBucketSpec(t *testing.T) {
9292
),
9393
),
9494
OneOf(
95-
Path(
96-
Call("invalid region format in spec", func(ctx context.Context, mck Mock) {
97-
}),
98-
Result("error", func(ctx context.Context, mck Mock) {
99-
bucket := bucket
100-
bucket.Spec.Region = "123invalid"
101-
assert.NotNil(t, objvalidator.validateLinodeObjectStorageBucketSpec(ctx, &bucket, mck.LinodeClient, false))
102-
}),
103-
),
104-
Path(
105-
Call("invalid region format in spec", func(ctx context.Context, mck Mock) {
106-
}),
107-
Result("error", func(ctx context.Context, mck Mock) {
108-
bucket := bucket
109-
bucket.Spec.Region = "invalid-2-2"
110-
assert.NotNil(t, objvalidator.validateLinodeObjectStorageBucketSpec(ctx, &bucket, mck.LinodeClient, false))
111-
}),
112-
),
11395
Path(
11496
Call("region ID not present", func(ctx context.Context, mck Mock) {
11597
mck.LinodeClient.EXPECT().GetRegion(gomock.Any(), gomock.Any()).Return(nil, errors.New("invalid region")).AnyTimes()

internal/webhook/v1alpha2/webhook_helpers.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"net/http"
2323
"os"
24-
"regexp"
2524
"slices"
2625
"time"
2726

@@ -80,34 +79,6 @@ func validateLinodeType(ctx context.Context, linodegoclient clients.LinodeClient
8079
return plan, nil
8180
}
8281

83-
// validateObjectStorageRegion validates an Object Storage deployment's region ID via the following rules:
84-
// - The Region ID is in the form: REGION_ID.
85-
// - The region has Object Storage support.
86-
//
87-
// NOTE: This implementation intended to bypass the authentication requirement for the [Clusters List] and [Cluster
88-
// View] endpoints in the Linode API, thereby reusing a [github.com/linode/linodego.Client] (and its caching if enabled)
89-
// across many admission requests.
90-
//
91-
// [Clusters List]: https://www.linode.com/docs/api/object-storage/#clusters-list
92-
// [Cluster View]: https://www.linode.com/docs/api/object-storage/#cluster-view
93-
94-
func validateObjectStorageRegion(ctx context.Context, linodegoclient clients.LinodeClient, id string, path *field.Path) *field.Error {
95-
// TODO: instrument with tracing, might need refactor to preserve readibility
96-
97-
cexp := regexp.MustCompile("^(([[:lower:]]+-)*[[:lower:]]+)$")
98-
cexp1 := regexp.MustCompile(`^(([[:lower:]]+-)*[[:lower:]]+)-\d+$`)
99-
if !cexp.MatchString(id) && !cexp1.MatchString(id) {
100-
return field.Invalid(path, id, "must be in form: region_id or region_id-ordinal")
101-
}
102-
var region string
103-
if cexp.FindStringSubmatch(id) != nil {
104-
region = cexp.FindStringSubmatch(id)[0]
105-
} else {
106-
region = cexp1.FindStringSubmatch(id)[1]
107-
}
108-
return validateRegion(ctx, linodegoclient, region, path, linodego.CapabilityObjectStorage)
109-
}
110-
11182
func getCredentialDataFromRef(ctx context.Context, crClient clients.K8sClient, credentialsRef corev1.SecretReference, defaultNamespace string) ([]byte, error) {
11283
credSecret, err := getCredentials(ctx, crClient, credentialsRef, defaultNamespace)
11384
if err != nil {

0 commit comments

Comments
 (0)