-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve apiVersion deprecation comments
Replace the deprecation comments in the SDKs with more relevant information, and emit warnings when resources are created using deprecated apiVersions.
- Loading branch information
1 parent
8912a60
commit 0d642a9
Showing
33 changed files
with
440 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kinds | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
func gvkStr(gvk schema.GroupVersionKind) string { | ||
return gvk.GroupVersion().String() + "/" + gvk.Kind | ||
} | ||
|
||
// DeprecatedApiVersion returns true if the given GVK is deprecated in the most recent k8s release. | ||
func DeprecatedApiVersion(gvk schema.GroupVersionKind) bool { | ||
return SuggestedApiVersion(gvk) != gvkStr(gvk) | ||
} | ||
|
||
// SuggestedApiVersion returns a string with the suggested apiVersion for a given GVK. | ||
// This is used to provide useful warning messages when a user creates a resource using a deprecated GVK. | ||
func SuggestedApiVersion(gvk schema.GroupVersionKind) string { | ||
switch gvk.GroupVersion() { | ||
case schema.GroupVersion{Group: "apps", Version: "v1beta1"}, | ||
schema.GroupVersion{Group: "apps", Version: "v1beta2"}: | ||
return "apps/v1/" + gvk.Kind | ||
case schema.GroupVersion{Group: "extensions", Version: "v1beta1"}: | ||
switch Kind(gvk.Kind) { | ||
case DaemonSet, Deployment, NetworkPolicy, ReplicaSet: | ||
return "apps/v1/" + gvk.Kind | ||
case Ingress: | ||
return "networking/v1beta1/" + gvk.Kind | ||
case PodSecurityPolicy: | ||
return "policy/v1beta1/" + gvk.Kind | ||
default: | ||
return gvkStr(gvk) | ||
} | ||
default: | ||
return gvkStr(gvk) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2016-2019, Pulumi Corporation. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package kinds | ||
|
||
import ( | ||
"testing" | ||
|
||
. "k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
func TestDeprecatedApiVersion(t *testing.T) { | ||
tests := []struct { | ||
gvk GroupVersionKind | ||
want bool | ||
}{ | ||
{GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, false}, | ||
{GroupVersionKind{Group: "apps", Version: "v1beta1", Kind: "Deployment"}, true}, | ||
{GroupVersionKind{Group: "apps", Version: "v1beta2", Kind: "Deployment"}, true}, | ||
{GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "DaemonSet"}, true}, | ||
{GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "Deployment"}, true}, | ||
{GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "Ingress"}, true}, | ||
{GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "NetworkPolicy"}, true}, | ||
{GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "PodSecurityPolicy"}, true}, | ||
{GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "ReplicaSet"}, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.gvk.String(), func(t *testing.T) { | ||
if got := DeprecatedApiVersion(tt.gvk); got != tt.want { | ||
t.Errorf("DeprecatedApiVersion() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSuggestedApiVersion(t *testing.T) { | ||
tests := []struct { | ||
gvk GroupVersionKind | ||
want string | ||
}{ | ||
// Deprecated ApiVersions return the suggested version string. | ||
{ | ||
GroupVersionKind{Group: "apps", Version: "v1beta1", Kind: "Deployment"}, | ||
"apps/v1/Deployment", | ||
}, | ||
{ | ||
GroupVersionKind{Group: "apps", Version: "v1beta2", Kind: "Deployment"}, | ||
"apps/v1/Deployment", | ||
}, | ||
{ | ||
GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "Deployment"}, | ||
"apps/v1/Deployment", | ||
}, | ||
{ | ||
GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "Ingress"}, | ||
"networking/v1beta1/Ingress", | ||
}, | ||
{ | ||
GroupVersionKind{Group: "extensions", Version: "v1beta1", Kind: "PodSecurityPolicy"}, | ||
"policy/v1beta1/PodSecurityPolicy", | ||
}, | ||
// Current ApiVersions return the same version string. | ||
{ | ||
GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}, | ||
"apps/v1/Deployment", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.gvk.String(), func(t *testing.T) { | ||
if got := SuggestedApiVersion(tt.gvk); got != tt.want { | ||
t.Errorf("SuggestedApiVersion() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.