Skip to content

Commit

Permalink
corresponding webbook changes
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Rancourt <kent.rancourt@gmail.com>
  • Loading branch information
krancour committed Feb 2, 2024
1 parent ea8aaba commit bb2c5a2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
29 changes: 28 additions & 1 deletion internal/webhook/warehouse/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package warehouse
import (
"context"
"fmt"
"strings"

"github.com/Masterminds/semver"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -179,15 +180,41 @@ func (w *webhook) validateImageSub(
return errs
}

// TODO: KR: This needs to be modified to make name required if the chart URL
// starts with http/s and forbidden if it starts with oci://
func (w *webhook) validateChartSub(
f *field.Path,
sub kargoapi.ChartSubscription,
) field.ErrorList {
errs := field.ErrorList{}
if err := validateSemverConstraint(
f.Child("semverConstraint"),
sub.SemverConstraint,
); err != nil {
return field.ErrorList{err}
errs = append(errs, err)
}
if strings.HasPrefix(sub.RepoURL, "oci://") && sub.Name != "" {
errs = append(
errs,
field.Invalid(
f.Child("name"),
sub.Name,
"must be empty if repoURL starts with oci://",
),
)
}
if (strings.HasPrefix(sub.RepoURL, "http://") || strings.HasPrefix(sub.RepoURL, "https://")) && sub.Name == "" {
errs = append(
errs,
field.Invalid(
f.Child("name"),
sub.Name,
"must be non-empty if repoURL starts with http:// or https://",
),
)
}
if len(errs) > 0 {
return errs
}
return nil
}
Expand Down
31 changes: 30 additions & 1 deletion internal/webhook/warehouse/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,10 @@ func TestValidateChartSub(t *testing.T) {
assertions func(field.ErrorList)
}{
{
name: "invalid",
name: "invalid semverConstraint and oci repoURL with name",
sub: kargoapi.ChartSubscription{
RepoURL: "oci://fake-url",
Name: "should-not-be-here",
SemverConstraint: "bogus",
},
assertions: func(errs field.ErrorList) {
Expand All @@ -503,6 +505,33 @@ func TestValidateChartSub(t *testing.T) {
Field: "chart.semverConstraint",
BadValue: "bogus",
},
{
Type: field.ErrorTypeInvalid,
Field: "chart.name",
BadValue: "should-not-be-here",
Detail: "must be empty if repoURL starts with oci://",
},
},
errs,
)
},
},

{
name: "https repoURL without name",
sub: kargoapi.ChartSubscription{
RepoURL: "https://fake-url",
},
assertions: func(errs field.ErrorList) {
require.Equal(
t,
field.ErrorList{
{
Type: field.ErrorTypeInvalid,
Field: "chart.name",
BadValue: "",
Detail: "must be non-empty if repoURL starts with http:// or https://",
},
},
errs,
)
Expand Down
4 changes: 2 additions & 2 deletions ui/src/features/project/project-details/nodes/repo-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const RepoNode = ({ nodeData, children }: Props) => {
const type = nodeData.type;
const value =
type === NodeType.REPO_CHART
? nodeData.data.registryUrl
? nodeData.data.repoUrl
: type === NodeType.WAREHOUSE
? nodeData.data
: nodeData.data.repoUrl;
Expand All @@ -43,7 +43,7 @@ export const RepoNode = ({ nodeData, children }: Props) => {
<div className={styles.body}>
{nodeData.type !== NodeType.WAREHOUSE && (
<div className='mb-2'>
{nodeData.type === NodeType.REPO_CHART ? 'Registry URL' : 'Repo URL'}
Repo URL
<Tooltip title={value}>
<a
href={
Expand Down

0 comments on commit bb2c5a2

Please sign in to comment.