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

Only show deprecation messages when new versions exist #1182

Merged
merged 9 commits into from
Jul 1, 2020

Conversation

komalali
Copy link
Member

@komalali komalali commented Jun 30, 2020

Proposed changes

We now check if the suggested kind exists in the current k8s cluster version before showing a deprecation message.

It's kind of a pain to figure out which kinds were added in which spec version, so I wrote a little node script to generate a list for me. Not sure if it's useful to put it somewhere, but I've pasted it here and open to ideas.

const fetch = require("node-fetch");

// Fetches the spec for the specified version and returns an array of keys for all the 
// definitions with the 'x-kubernetes-group-version-kind' property (signifying a GVK).
async function getSpec(version) {
    const response = await fetch(`https://raw.githubusercontent.com/kubernetes/kubernetes/release-1.${version}/api/openapi-spec/swagger.json`);
    const json = await response.json();
    const types = [];
    Object.entries(json.definitions).forEach(([key, val]) => {
        if (val['x-kubernetes-group-version-kind']) {
            types.push(key)
        }
    })
    return types;
}

// Map through the versions and collect all the resources that are not present in the 
// previous version.
(async function main() {
    const versions = [13, 14, 15, 16, 17, 18];
    const versionMap = {};
    const results = await Promise.all(versions.map(getSpec));
    results.forEach((result, index) => versionMap[`v${versions[index]}`] = result);

    const newResources = {};

    function getNewResources(version) {
        const newInVersion = [];
        versionMap[`v${version}`].forEach(resource => {
            if (!versionMap[`v${version - 1}`].includes(resource)) {
                newInVersion.push(resource);
            }
        })
        newResources[`v${version}`] = newInVersion;
    }

    for (let i=1; i<versions.length; i++) {
        getNewResources(versions[i])
    }

    console.log(newResources);
})()

Related issues (optional)

Fixes: #1168

@komalali komalali changed the title Komalali/k8s deprecations Only show deprecation messages when new versions exist Jun 30, 2020
@komalali komalali marked this pull request as ready for review June 30, 2020 16:21
Copy link
Member

@lblackstone lblackstone left a comment

Choose a reason for hiding this comment

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

LGTM overall!

provider/pkg/kinds/deprecated.go Outdated Show resolved Hide resolved
provider/cmd/pulumi-gen-kubernetes/main.go Show resolved Hide resolved
@lblackstone
Copy link
Member

It's kind of a pain to figure out which kinds were added in which spec version, so I wrote a little node script to generate a list for me. Not sure if it's useful to put it somewhere, but I've pasted it here and open to ideas.

We may eventually want to turn this into something that runs as part of code generation (translated to Go). Can you open an issue to track that?

@komalali komalali requested a review from lblackstone July 1, 2020 00:08
Copy link
Member

@lblackstone lblackstone left a comment

Choose a reason for hiding this comment

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

One more fix, and then LGTM

provider/pkg/kinds/deprecated.go Outdated Show resolved Hide resolved
@komalali komalali requested a review from lblackstone July 1, 2020 16:16
@lblackstone lblackstone merged commit 6b6db88 into master Jul 1, 2020
@pulumi-bot pulumi-bot deleted the komalali/k8s-deprecations branch July 1, 2020 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation warnings are shown for resources that cannot be upgraded in the target k8s cluster
2 participants