-
Notifications
You must be signed in to change notification settings - Fork 31
Add SkaffoldYamlGenerator #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5958ceb
Add SkaffoldYamlGenerator
TadCordle a82ea02
Make expected output local
TadCordle c28057a
Move test yaml to file
TadCordle 5b79548
Fix comments
TadCordle 4ee1230
Fix windows test, rename test resource, use String instead of Path
TadCordle cda37fa
Merge branch 'master' of github.com:GoogleContainerTools/skaffold-too…
TadCordle 05cc9bd
Charset
TadCordle 524546a
Merge branch 'master' of github.com:GoogleContainerTools/skaffold-too…
TadCordle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...lugins-core/src/main/java/com/google/cloud/tools/skaffold/yaml/SkaffoldYamlGenerator.java
This file contains hidden or 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,61 @@ | ||
| /* | ||
| * Copyright 2018 Google LLC. All rights reserved. | ||
| * | ||
| * 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 com.google.cloud.tools.skaffold.yaml; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| /** | ||
| * Automatically generates contents of a skaffold.yaml from a provided set of Kubernetes manifests. | ||
| */ | ||
| public class SkaffoldYamlGenerator { | ||
|
|
||
| private final ImmutableList<String> manifestPaths; | ||
|
|
||
| /** | ||
| * Creates a new {@link SkaffoldYamlGenerator}. | ||
| * | ||
| * @param manifestPaths a non-empty list of paths to Kubernetes yamls (may include glob patterns) | ||
| */ | ||
| public SkaffoldYamlGenerator(ImmutableList<String> manifestPaths) { | ||
| Preconditions.checkArgument(manifestPaths.size() > 0); | ||
| this.manifestPaths = manifestPaths; | ||
| } | ||
|
|
||
| /** | ||
| * Generates the skaffold.yaml contents. | ||
| * | ||
| * @return the skaffold.yaml contents as a string | ||
| */ | ||
| public String generate() { | ||
| StringBuilder output = new StringBuilder(); | ||
| output.append("apiVersion: skaffold/v1alpha2\n"); | ||
| output.append("kind: Config\n"); | ||
| output.append("deploy:\n"); | ||
| output.append(" kubectl:\n"); | ||
|
|
||
| // Add manifests | ||
| output.append(" manifests:\n"); | ||
| for (String manifestPath : manifestPaths) { | ||
| output.append(" - "); | ||
| output.append(manifestPath); | ||
| output.append("\n"); | ||
| } | ||
|
|
||
| return output.toString(); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...ns-core/src/test/java/com/google/cloud/tools/skaffold/yaml/SkaffoldYamlGeneratorTest.java
This file contains hidden or 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,48 @@ | ||
| /* | ||
| * Copyright 2018 Google LLC. All rights reserved. | ||
| * | ||
| * 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 com.google.cloud.tools.skaffold.yaml; | ||
|
|
||
| import com.google.common.base.Joiner; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.io.Resources; | ||
| import java.io.IOException; | ||
| import java.net.URISyntaxException; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Paths; | ||
| import java.util.List; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| /** Tests for {@link SkaffoldYamlGenerator}. */ | ||
| public class SkaffoldYamlGeneratorTest { | ||
|
|
||
| @Test | ||
| public void testGenerate() throws URISyntaxException, IOException { | ||
| // Read all lines and join with \n to avoid Windows test failing | ||
| List<String> lines = | ||
| Files.readAllLines( | ||
| Paths.get(Resources.getResource("SkaffoldYamlGeneratorTest/generated.yaml").toURI()), | ||
| StandardCharsets.UTF_8); | ||
| String expected = Joiner.on('\n').join(lines) + "\n"; | ||
|
|
||
| ImmutableList<String> paths = ImmutableList.of("MANIFEST_PATH_1", "MANIFEST_PATH_2"); | ||
| SkaffoldYamlGenerator generator = new SkaffoldYamlGenerator(paths); | ||
|
|
||
| Assert.assertEquals(expected, generator.generate()); | ||
| } | ||
| } | ||
7 changes: 7 additions & 0 deletions
7
skaffold-plugins-core/src/test/resources/SkaffoldYamlGeneratorTest/generated.yaml
This file contains hidden or 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,7 @@ | ||
| apiVersion: skaffold/v1alpha2 | ||
| kind: Config | ||
| deploy: | ||
| kubectl: | ||
| manifests: | ||
| - MANIFEST_PATH_1 | ||
| - MANIFEST_PATH_2 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should include charset here.