Skip to content

Commit

Permalink
webhook: check duration format
Browse files Browse the repository at this point in the history
  • Loading branch information
l1b0k committed Dec 5, 2023
1 parent 4e026aa commit 4b998fa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/controller/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"time"

"github.com/AliyunContainerService/terway/pkg/apis/network.alibabacloud.com/v1beta1"

Expand Down Expand Up @@ -45,6 +46,15 @@ func ValidateHook() *webhook.Admission {
if len(podNetworking.Spec.SecurityGroupIDs) > 5 {
return admission.Denied("security group can not more than 5")
}

if podNetworking.Spec.AllocationType.ReleaseStrategy == v1beta1.IPAllocTypeFixed {
if podNetworking.Spec.AllocationType.ReleaseStrategy == v1beta1.ReleaseStrategyTTL {
_, err = time.ParseDuration(podNetworking.Spec.AllocationType.ReleaseAfter)
if err != nil {
return webhook.Denied(fmt.Sprintf("invalid releaseAfter %s", podNetworking.Spec.AllocationType.ReleaseAfter))
}
}
}
return webhook.Allowed("checked")
}),
}
Expand Down

0 comments on commit 4b998fa

Please sign in to comment.