Skip to content

Commit

Permalink
Merge pull request #157 from vshn/webhook/pg_length
Browse files Browse the repository at this point in the history
Reduce max length even further
  • Loading branch information
Kidswiss authored Apr 30, 2024
2 parents e4c123a + 2b8f820 commit 5ab2b6c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/controller/webhooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ webhooks:
- UPDATE
- DELETE
resources:
- postgresqls
- vshnpostgresqls
sideEffects: None
- admissionReviewVersions:
- v1
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/webhooks/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

// See https://book.kubebuilder.io/reference/markers/webhook for docs
//+kubebuilder:webhook:verbs=create;update;delete,path=/validate-vshn-appcat-vshn-io-v1-vshnpostgresql,mutating=false,failurePolicy=fail,groups=vshn.appcat.vshn.io,resources=postgresqls,versions=v1,name=postgresql.vshn.appcat.vshn.io,sideEffects=None,admissionReviewVersions=v1
//+kubebuilder:webhook:verbs=create;update;delete,path=/validate-vshn-appcat-vshn-io-v1-vshnpostgresql,mutating=false,failurePolicy=fail,groups=vshn.appcat.vshn.io,resources=vshnpostgresqls,versions=v1,name=postgresql.vshn.appcat.vshn.io,sideEffects=None,admissionReviewVersions=v1

//RBAC
//+kubebuilder:rbac:groups=vshn.appcat.vshn.io,resources=xvshnpostgresqls,verbs=get;list;watch;patch;update
Expand Down Expand Up @@ -86,7 +86,7 @@ func (p *PostgreSQLWebhookHandler) ValidateCreate(ctx context.Context, obj runti
if err != nil {
allErrs = append(allErrs, &field.Error{
Field: ".metadata.name",
Detail: fmt.Sprintf("Please shorten PostgreSQL name, currently it is: %s",
Detail: fmt.Sprintf("Please shorten PostgreSQL name to 30 characters or less: %s",
err.Error()),
BadValue: pg.GetName(),
Type: field.ErrorTypeTooLong,
Expand Down Expand Up @@ -274,11 +274,11 @@ func (p *PostgreSQLWebhookHandler) checkGuaranteedAvailability(ctx context.Conte
return fieldErrs
}

// k8s limitation is 52 characters, our longest postfix we add is 15 character, therefore 37 chracters is the maximum length
// k8s limitation is 56 characters, longest postfix for sgbackups is 26 character, therefore 30 chracters is the maximum length
// https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
func (r *PostgreSQLWebhookHandler) validateResourceNameLength(name string) error {
if len(name) > 37 {
return fmt.Errorf("name is too long: %d. We add various postfixes and CronJob name length has it's own limitations: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names", len(name))
if len(name) > 30 {
return fmt.Errorf("current length: %d. We add various postfixes and CronJob name length has it's own limitations: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names", len(name))
}
return nil
}

0 comments on commit 5ab2b6c

Please sign in to comment.