openrewrite / rewrite-kubernetes

OpenRewrite recipes for Kubernetes.
Apache License 2.0
9 stars 8 forks source link

Markers are left in all yaml files when running recipes with maven or gradle plugin #51

Closed smwhit closed 3 months ago

smwhit commented 3 months ago

I am using

If I run either ./gradlew --init-script=init.gradle rewriteRun against

initscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2" }
    }
    dependencies { classpath("org.openrewrite:plugin:6.16.4") }
}
rootProject {
    plugins.apply(org.openrewrite.gradle.RewritePlugin)
    dependencies {
        rewrite("org.openrewrite.recipe:rewrite-kubernetes:2.7.1")
    }
    rewrite {
        activeRecipe("org.openrewrite.kubernetes.KubernetesBestPractices")
    }
    afterEvaluate {
        if (repositories.isEmpty()) {
            repositories {
                mavenCentral()
            }
        }
    }
}

or

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-kubernetes:RELEASE -Drewrite.activeRecipes=org.openrewrite.kubernetes.KubernetesBestPractices -Drewrite.exportDatatables=true

against a very simple spring boot project (https://github.com/smwhit/openrewrite-playground/tree/main/kubernetes-test) there ends up being markers left in the yaml files

-apiVersion: apps/v1
+~~>~~>apiVersion: apps/v1

Slack conversation started https://rewriteoss.slack.com/archives/C01A843MWG5/p1722337226396179

timtebeek commented 3 months ago

I've for now replicated the issue with unit tests; now we need to explore a fix.

timtebeek commented 3 months ago

Now fixed on the main branch @smwhit ; Could you let us know if you indeed see improvement with our snapshot versions?

smwhit commented 3 months ago

Hi @timtebeek , I have updated to use snapshots and looks like init.gradle is pulling org.openrewrite.recipe:rewrite-kubernetes:latest.integration -> 2.9.0-SNAPSHOT

I still see markers left in deployment.yaml in my test project, although not in the spring yaml files.

See - https://github.com/smwhit/openrewrite-playground/commit/67f1c19956e112f5e71e1a98908a2386a1904306 for how I updated to use openrewrite snapshots.

timtebeek commented 3 months ago

Hi @smwhit ; Good to hear the markers have disappeared from the spring yaml files. The markers you're still seeing are likely search hits coming from recipes using FindResourceMissingConfiguration. This should improve their usability: https://github.com/openrewrite/rewrite-kubernetes/commit/4de5c226006275924b3651ff103bf67f66d3c162

Hope that helps & appreciate the feedback; this really helps us improve. :)

smwhit commented 3 months ago

That's a great devex change

timtebeek commented 3 months ago

Glad to hear! Sounds like you've found something useful using these patterns. Of course finding is typically just the first step we aim for; with swiss-army-tool MergeYaml (recent video) you can then insert snippets as needed to add those missing elements.

If you come up with any new uses for these recipes, or recipes of your own, do feel welcome to contribute even a rough draft. We'd love to expand these recipes.

One thing I'd been eyeing is the ever changing api versions; I think we should be able to help you update those as you move from one version to another.