From 367340d1b8907dd8f2e22a85c82552ce65cdac26 Mon Sep 17 00:00:00 2001 From: Gustav Westling Date: Mon, 10 Aug 2020 20:34:42 +0200 Subject: [PATCH] score/stable: recommend Ingress networking.k8s.io/v1beta1 if using Kubernetes v1.14 or newer --- config/config.go | 5 +++++ score/stable/stable_version.go | 3 ++- score/stable/stable_version_test.go | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 84c8fdcb..1416a4a5 100644 --- a/config/config.go +++ b/config/config.go @@ -2,6 +2,7 @@ package config import ( "errors" + "fmt" "io" "strconv" "strings" @@ -65,3 +66,7 @@ func (s Semver) LessThan(other Semver) bool { } return false } + +func (s Semver) String() string { + return fmt.Sprintf("v%d.%d", s.Major, s.Minor) +} diff --git a/score/stable/stable_version.go b/score/stable/stable_version.go index 8842fda0..f18905c5 100644 --- a/score/stable/stable_version.go +++ b/score/stable/stable_version.go @@ -25,6 +25,7 @@ func metaStableAvailable(kubernetsVersion config.Semver) func(meta domain.BothMe "extensions/v1beta1": { "Deployment": recommendedApi{"apps/v1", config.Semver{1, 9}}, "DaemonSet": recommendedApi{"apps/v1", config.Semver{1, 9}}, + "Ingress": recommendedApi{"networking.k8s.io/v1beta1", config.Semver{1, 14}}, }, "apps/v1beta1": { "Deployment": recommendedApi{"apps/v1", config.Semver{1, 9}}, @@ -51,7 +52,7 @@ func metaStableAvailable(kubernetsVersion config.Semver) func(meta domain.BothMe score.Grade = scorecard.GradeWarning score.AddComment("", fmt.Sprintf("The apiVersion and kind %s/%s is deprecated", meta.TypeMeta.APIVersion, meta.TypeMeta.Kind), - fmt.Sprintf("It's recommended to use %s instead", recAPI.newAPI), + fmt.Sprintf("It's recommended to use %s instead which has been available since Kubernetes %s", recAPI.newAPI, recAPI.availableSince.String()), ) return } diff --git a/score/stable/stable_version_test.go b/score/stable/stable_version_test.go index 94730992..ba0fc9e5 100644 --- a/score/stable/stable_version_test.go +++ b/score/stable/stable_version_test.go @@ -21,5 +21,12 @@ func TestStableVersionNewKubernetesVersion(t *testing.T) { newKubernetes := metaStableAvailable(config.Semver{1, 18}) scoreNew := newKubernetes(ks.BothMeta{TypeMeta: v1.TypeMeta{Kind: "Deployment", APIVersion: "extensions/v1beta1"}}) assert.Equal(t, scorecard.GradeWarning, scoreNew.Grade) - assert.Equal(t, []scorecard.TestScoreComment{{Path: "", Summary: "The apiVersion and kind extensions/v1beta1/Deployment is deprecated", Description: "It's recommended to use apps/v1 instead", DocumentationURL: ""}}, scoreNew.Comments) + assert.Equal(t, []scorecard.TestScoreComment{{Path: "", Summary: "The apiVersion and kind extensions/v1beta1/Deployment is deprecated", Description: "It's recommended to use apps/v1 instead which has been available since Kubernetes v1.9", DocumentationURL: ""}}, scoreNew.Comments) +} + +func TestStableVersionIngress(t *testing.T) { + newKubernetes := metaStableAvailable(config.Semver{1, 18}) + scoreNew := newKubernetes(ks.BothMeta{TypeMeta: v1.TypeMeta{Kind: "Ingress", APIVersion: "extensions/v1beta1"}}) + assert.Equal(t, scorecard.GradeWarning, scoreNew.Grade) + assert.Equal(t, []scorecard.TestScoreComment{{Path: "", Summary: "The apiVersion and kind extensions/v1beta1/Ingress is deprecated", Description: "It's recommended to use networking.k8s.io/v1beta1 instead which has been available since Kubernetes v1.14", DocumentationURL: ""}}, scoreNew.Comments) }