Skip to content

Commit

Permalink
Merge pull request #265 from lmiccini/redis-crmaxlength
Browse files Browse the repository at this point in the history
Add CrMaxLengthCorrection to Redis
  • Loading branch information
openshift-merge-bot[bot] authored Sep 6, 2024
2 parents 02c98ff + dd831a2 commit 12ffed6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions apis/redis/v1beta1/redis_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const (

// RedisContainerImage is the fall-back container image for Redis
RedisContainerImage = "quay.io/podified-antelope-centos9/openstack-redis:current-podified"

// CrMaxLengthCorrection - DNS1123LabelMaxLength (63) - CrMaxLengthCorrection used in validation to
// omit issue with statefulset pod label "controller-revision-hash": "<statefulset_name>-<hash>"
// Int32 is a 10 character + hyphen = 11
CrMaxLengthCorrection = 11
)

// RedisSpec defines the desired state of Redis
Expand Down
23 changes: 21 additions & 2 deletions apis/redis/v1beta1/redis_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ limitations under the License.
package v1beta1

import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
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"

common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
)

// RedisDefaults -
Expand Down Expand Up @@ -86,8 +91,22 @@ var _ webhook.Validator = &Redis{}
func (r *Redis) ValidateCreate() (admission.Warnings, error) {
redislog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil, nil
var allErrs field.ErrorList
var allWarn []string

allErrs = common_webhook.ValidateDNS1123Label(
field.NewPath("metadata").Child("name"),
[]string{r.Name},
CrMaxLengthCorrection) // omit issue with statefulset pod label "controller-revision-hash": "<statefulset_name>-<hash>"

if len(allErrs) != 0 {
return allWarn, apierrors.NewInvalid(
schema.GroupKind{Group: "redis.openstack.org", Kind: "Redis"},
r.Name, allErrs)
}

return allWarn, nil

}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
Expand Down

0 comments on commit 12ffed6

Please sign in to comment.