Skip to content

Commit

Permalink
Update deprecation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Apr 5, 2021
1 parent fbc1d98 commit 8341834
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
52 changes: 51 additions & 1 deletion provider/pkg/kinds/deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ import (
// storage/v1beta1/* / 1.19 / _
// https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.19.md#deprecation-1
//
// batch/v2alpha1/CronJob / 1.21 / 1.21
// discovery/v1beta1/EndpointSlice / 1.21 / 1.25
// */PodSecurityPolicy / 1.21 / 1.25
// https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.21.md#deprecation-1
// TODO: Keep updating this list on every release.

var v18 = cluster.ServerVersion{Major: 1, Minor: 8}
Expand All @@ -79,7 +83,9 @@ var v117 = cluster.ServerVersion{Major: 1, Minor: 17}
var v118 = cluster.ServerVersion{Major: 1, Minor: 18}
var v119 = cluster.ServerVersion{Major: 1, Minor: 19}
var v120 = cluster.ServerVersion{Major: 1, Minor: 20}
var v121 = cluster.ServerVersion{Major: 1, Minor: 21}
var v122 = cluster.ServerVersion{Major: 1, Minor: 22}
var v125 = cluster.ServerVersion{Major: 1, Minor: 25}

func gvkStr(gvk schema.GroupVersionKind) string {
return gvk.GroupVersion().String() + "/" + gvk.Kind
Expand Down Expand Up @@ -147,6 +153,11 @@ func AddedInVersion(gvk *schema.GroupVersionKind) *cluster.ServerVersion {
case HorizontalPodAutoscaler, HorizontalPodAutoscalerList:
return &v112
}
case BatchV1:
switch k {
case CronJob, CronJobList:
return &v121
}
case CoordinationV1B1:
switch k {
case Lease, LeaseList:
Expand All @@ -157,11 +168,21 @@ func AddedInVersion(gvk *schema.GroupVersionKind) *cluster.ServerVersion {
case Lease, LeaseList:
return &v114
}
case CoreV1:
switch k {
case EphemeralContainers:
return &v121
}
case DiscoveryV1B1:
switch k {
case EndpointSlice, EndpointSliceList:
return &v117
}
case DiscoveryV1:
switch k {
case EndpointSlice, EndpointSliceList:
return &v121
}
case FlowcontrolV1A1:
switch k {
case FlowSchema, FlowSchemaList, PriorityLevelConfiguration, PriorityLevelConfigurationList:
Expand All @@ -184,6 +205,11 @@ func AddedInVersion(gvk *schema.GroupVersionKind) *cluster.ServerVersion {
case PodSecurityPolicy, PodSecurityPolicyList:
return &v110
}
case PolicyV1:
switch k {
case PodDisruptionBudget, PodDisruptionBudgetList:
return &v121
}
case SchedulingV1B1:
switch k {
case PriorityClass, PriorityClassList:
Expand All @@ -194,12 +220,19 @@ func AddedInVersion(gvk *schema.GroupVersionKind) *cluster.ServerVersion {
case PriorityClass, PriorityClassList:
return &v114
}
case StorageV1A1:
switch k {
case CSIStorageCapacity, CSIStorageCapacityList:
return &v121
}
case StorageV1B1:
switch k {
case VolumeAttachment, VolumeAttachmentList:
return &v110
case CSIDriver, CSIDriverList, CSINode, CSINodeList:
return &v114
case CSIStorageCapacity, CSIStorageCapacityList:
return &v121
}
case StorageV1:
switch k {
Expand Down Expand Up @@ -232,6 +265,11 @@ func ExistsInVersion(gvk *schema.GroupVersionKind, version *cluster.ServerVersio
func RemovedInVersion(gvk schema.GroupVersionKind) *cluster.ServerVersion {
gv, k := groupVersion(gvk.GroupVersion().String()), Kind(gvk.Kind)

switch k {
case PodSecurityPolicy, PodSecurityPolicyList:
return &v125
}

switch gv {
case AdmissionregistrationV1B1:
return &v122
Expand All @@ -241,8 +279,12 @@ func RemovedInVersion(gvk schema.GroupVersionKind) *cluster.ServerVersion {
return &v122
case AuthorizationV1B1:
return &v122
case BatchV2A1:
return &v121
case CoordinationV1B1:
return &v122
case DiscoveryV1B1:
return &v125
case ExtensionsV1B1, AppsV1B1, AppsV1B2:
if k == Ingress || k == IngressList {
return &v120
Expand Down Expand Up @@ -290,8 +332,12 @@ func SuggestedAPIVersion(gvk schema.GroupVersionKind) string {
return fmt.Sprintf(gvkFmt, AuthorizationV1, k)
case AutoscalingV2B1:
return fmt.Sprintf(gvkFmt, AutoscalingV1, k)
case BatchV2A1:
return fmt.Sprintf(gvkFmt, BatchV1B1, k) // TODO: update this to batch/v1 at v1.25
case CoordinationV1B1:
return fmt.Sprintf(gvkFmt, CoordinationV1, k)
case DiscoveryV1B1:
return fmt.Sprintf(gvkFmt, DiscoveryV1, k)
case ExtensionsV1B1:
switch k {
case DaemonSet, DaemonSetList, Deployment, DeploymentList, ReplicaSet, ReplicaSetList:
Expand Down Expand Up @@ -325,7 +371,11 @@ func upstreamDocsLink(version cluster.ServerVersion) string {
return "https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.17.md#deprecations-and-removals"
case v119:
return "https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.19.md#deprecation-1"
// TODO: 1.20
case v120:
return "https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.20.md#deprecation"
case v121:
return "https://git.k8s.io/kubernetes/CHANGELOG/CHANGELOG-1.21.md#deprecation"
// TODO: 1.22
default:
return ""
}
Expand Down
8 changes: 8 additions & 0 deletions provider/pkg/kinds/deprecated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func TestDeprecatedApiVersion(t *testing.T) {
{toGVK(AuthorizationV1B1, SelfSubjectRulesReview), nil, true},
{toGVK(AuthorizationV1B1, SubjectAccessReview), nil, true},
{toGVK(AutoscalingV2B1, HorizontalPodAutoscaler), nil, true},
{toGVK(BatchV2A1, CronJob), &v121, true},
{toGVK(CoordinationV1B1, Lease), nil, true},
{toGVK(DiscoveryV1B1, EndpointSlice), &v121, true},
{toGVK(ExtensionsV1B1, DaemonSet), nil, true},
{toGVK(ExtensionsV1B1, Deployment), nil, true},
{toGVK(ExtensionsV1B1, Ingress), nil, true},
Expand Down Expand Up @@ -155,7 +157,9 @@ func TestSuggestedApiVersion(t *testing.T) {
{toGVK(AuthenticationV1B1, TokenReview), wantStr(AuthenticationV1, TokenReview)},
{toGVK(AuthorizationV1B1, LocalSubjectAccessReview), wantStr(AuthorizationV1, LocalSubjectAccessReview)},
{toGVK(AutoscalingV2B1, HorizontalPodAutoscaler), wantStr(AutoscalingV1, HorizontalPodAutoscaler)},
{toGVK(BatchV2A1, CronJob), wantStr(BatchV1B1, CronJob)},
{toGVK(CoordinationV1B1, Lease), wantStr(CoordinationV1, Lease)},
{toGVK(DiscoveryV1B1, EndpointSlice), wantStr(DiscoveryV1, EndpointSlice)},
{toGVK(ExtensionsV1B1, DaemonSet), wantStr(AppsV1, DaemonSet)},
{toGVK(ExtensionsV1B1, Deployment), wantStr(AppsV1, Deployment)},
{toGVK(ExtensionsV1B1, DeploymentList), wantStr(AppsV1, DeploymentList)},
Expand Down Expand Up @@ -198,11 +202,15 @@ func TestRemovedInVersion(t *testing.T) {
{toGVK(AppsV1B2, Deployment), &v116},
{toGVK(AuthenticationV1B1, TokenReview), &v122},
{toGVK(AuthorizationV1B1, LocalSubjectAccessReview), &v122},
{toGVK(BatchV2A1, CronJob), &v121},
{toGVK(CoordinationV1B1, Lease), &v122},
{toGVK(DiscoveryV1B1, EndpointSlice), &v125},
{toGVK(ExtensionsV1B1, Deployment), &v116},
{toGVK(ExtensionsV1B1, DeploymentList), &v116},
{toGVK(ExtensionsV1B1, Ingress), &v120},
{toGVK(ExtensionsV1B1, IngressList), &v120},
{toGVK(ExtensionsV1B1, PodSecurityPolicy), &v125},
{toGVK(PolicyV1B1, PodSecurityPolicy), &v125},
{toGVK(RbacV1A1, ClusterRole), &v122},
{toGVK(RbacV1B1, ClusterRole), &v122},
{toGVK(SchedulingV1A1, PriorityClass), &v117},
Expand Down

0 comments on commit 8341834

Please sign in to comment.