Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion internal/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ func NewChartResolverWithURLs(client goHelm.Client, v1URL, v2URL string) *ChartR

// ChartIsV2Plus returns true if the chart version is v2.0.0 or higher
func ChartIsV2Plus(v string) bool {
return ChartEqualsOrHigherVersion(v, "v2.0.0")
}

// ChartIsV1_8Plus returns true if the chart version is v1.8.0 or higher
func ChartIsV1_8Plus(v string) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using _ in golang methods names is discouraged

return ChartEqualsOrHigherVersion(v, "v1.8.0")
}

// ChartEqualsOrHigherVersion returns true if the chart version is equals or higher than threshold
func ChartEqualsOrHigherVersion(v string, threshold string) bool {
if v == "" {
return false
}
if v[0] != 'v' {
v = "v" + v
}
return semver.Compare(v, "v2.0.0") >= 0
return semver.Compare(v, threshold) >= 0
}

// ResolveChartReference resolves an Airbyte chart reference to its full URL/path and version.
Expand Down
71 changes: 71 additions & 0 deletions internal/helm/chart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,77 @@ func TestChartIsV2Plus(t *testing.T) {
}
}

func TestChartIsV1_8Plus(t *testing.T) {
tests := []struct {
name string
ver string
want bool
}{
{
name: "empty version",
ver: "",
want: false,
},
{
name: "v1 version",
ver: "1.0.0",
want: false,
},
{
name: "v1 with v prefix",
ver: "v1.0.0",
want: false,
},
{
name: "v1.8 version",
ver: "1.8.0",
want: true,
},
{
name: "v1.8 with v prefix",
ver: "v1.8.0",
want: true,
},
{
name: "v1.8.5 version",
ver: "1.8.5",
want: true,
},
{
name: "v1.8.5 with v prefix",
ver: "v1.8.5",
want: true,
},
{
name: "v2 version",
ver: "2.0.0",
want: true,
},
{
name: "v2 with v prefix",
ver: "v2.0.0",
want: true,
},
{
name: "v2 pre-release",
ver: "v2.0.0-alpha.1",
want: true,
},
{
name: "v3 version",
ver: "3.0.0",
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ChartIsV1_8Plus(tt.ver)
assert.Equal(t, tt.want, got)
})
}
}

func TestResolveChartReference(t *testing.T) {
t.Parallel()
ctrl := gomock.NewController(t)
Expand Down
6 changes: 3 additions & 3 deletions internal/k8s/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func Ingress(chartVersion string, hosts []string) *networkingv1.Ingress {
// ingressRule creates a rule for the host with proper API routing.
func ingressRules(chartVersion string, host string) networkingv1.IngressRule {
rules := ingressRulesForV1()
if helm.ChartIsV2Plus(chartVersion) {
rules = ingressRulesForV2()
if helm.ChartIsV1_8Plus(chartVersion) {
rules = ingressRulesForV1_8Plus()
}

return networkingv1.IngressRule{
Expand Down Expand Up @@ -98,7 +98,7 @@ func ingressRulesForV1() networkingv1.IngressRuleValue {
}
}

func ingressRulesForV2() networkingv1.IngressRuleValue {
func ingressRulesForV1_8Plus() networkingv1.IngressRuleValue {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using _ in golang methods names is discouraged

var pathType = networkingv1.PathType("Prefix")

return networkingv1.IngressRuleValue{
Expand Down