Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change k8s API removals from error to warning #1475

Merged
merged 1 commit into from
Feb 22, 2021
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (Unreleased)

- Change k8s API removals from error to warning (https://github.com/pulumi/pulumi-kubernetes/pull/1475)

## 2.8.1 (February 12, 2021)

- Skip Helm test hook resources by default (https://github.com/pulumi/pulumi-kubernetes/pull/1467)
Expand Down
22 changes: 22 additions & 0 deletions provider/pkg/await/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/pulumi/pulumi-kubernetes/provider/v2/pkg/clients"
"github.com/pulumi/pulumi-kubernetes/provider/v2/pkg/cluster"
"github.com/pulumi/pulumi-kubernetes/provider/v2/pkg/kinds"
"github.com/pulumi/pulumi-kubernetes/provider/v2/pkg/logging"
"github.com/pulumi/pulumi-kubernetes/provider/v2/pkg/metadata"
"github.com/pulumi/pulumi-kubernetes/provider/v2/pkg/openapi"
Expand Down Expand Up @@ -56,6 +57,7 @@ type ProviderConfig struct {
Host *pulumiprovider.HostClient
URN resource.URN
InitialAPIVersion string
ClusterVersion *cluster.ServerVersion

ClientSet *clients.DynamicClientSet
DedupLogger *logging.DedupLogger
Expand Down Expand Up @@ -117,6 +119,19 @@ func ResourceIDFromUnstructured(uns *unstructured.Unstructured) ResourceID {
}
}

// skipRetry checks if we should skip retrying creation for unresolvable errors.
func skipRetry(gvk schema.GroupVersionKind, k8sVersion *cluster.ServerVersion, err error,
) (bool, *cluster.ServerVersion) {
if meta.IsNoMatchError(err) {
// If the GVK is known to have been removed, it's not waiting on any CRD creation, and we can return early.
if removed, version := kinds.RemovedAPIVersion(gvk, *k8sVersion); removed {
return true, version
}
}

return false, nil
}

// Creation (as the usage, `await.Creation`, implies) will block until one of the following is true:
// (1) the Kubernetes resource is reported to be initialized; (2) the initialization timeout has
// occurred; or (3) an error has occurred while the resource was being initialized.
Expand Down Expand Up @@ -149,6 +164,13 @@ func Creation(c CreateConfig) (*unstructured.Unstructured, error) {
if client == nil {
client, err = c.ClientSet.ResourceClient(c.Inputs.GroupVersionKind(), c.Inputs.GetNamespace())
if err != nil {
if skip, version := skipRetry(c.Inputs.GroupVersionKind(), c.ClusterVersion, err); skip {
return &kinds.RemovedAPIError{
GVK: c.Inputs.GroupVersionKind(),
Version: version,
}
}

_ = c.Host.LogStatus(c.Context, diag.Info, c.URN, fmt.Sprintf(
"Retry #%d; creation failed: %v", i, err))
return err
Expand Down
6 changes: 3 additions & 3 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,8 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
// Skip the API version check if the cluster is unreachable.
if !k.clusterUnreachable {
if removed, version := kinds.RemovedAPIVersion(gvk, k.k8sVersion); removed {
return nil, &kinds.RemovedAPIError{GVK: gvk, Version: version}
}
if !k.suppressDeprecationWarnings && kinds.DeprecatedAPIVersion(gvk, &k.k8sVersion) {
_ = k.host.Log(ctx, diag.Warning, urn, (&kinds.RemovedAPIError{GVK: gvk, Version: version}).Error())
} else if !k.suppressDeprecationWarnings && kinds.DeprecatedAPIVersion(gvk, &k.k8sVersion) {
_ = k.host.Log(ctx, diag.Warning, urn, gen.APIVersionComment(gvk))
}
}
Expand Down Expand Up @@ -1497,6 +1496,7 @@ func (k *kubeProvider) Create(
Host: k.host,
URN: urn,
InitialAPIVersion: initialAPIVersion,
ClusterVersion: &k.k8sVersion,
ClientSet: k.clientSet,
DedupLogger: logging.NewLogger(k.canceler.context, k.host, urn),
Resources: resources,
Expand Down