-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(manifest): Some refactoring of manifest bakery classes (#444)
* refactor(manifest): Encapsulate paths in BakeManifestEnvironment Manifest bakes (helm, customize) create a BakeManifestEnviornment that encapsulates a staging directory. Instead of exposing the staging directory to consumers and requiring them to do the path operations, hide the actual staging path from consumers and instead expose operations to resovle paths relative to that path. A nice advantage of this is that we can pull the logic to ensure consumers don't break out of the staging path into the class. * fix(manifest): Clean up temporary directories in tests The tests I added in my last PR should have created the BakeManifestEnvironment in a try-with-resources construction (as happens in the real code) so that we clean up the temporary directories that are created. * refactor(manifest): Use a UUID as the file name When generating a file name for helm bakes, we take a hash of the artifact's reference (or if absent the name). Since we just need the name to be unique, let's just use a UUID to make the name generation simpler. * refactor(manifest): A few minor style fixes * Replace a loop over the enum TemplateRenderer's values with a call to valueOf * Remove unecessary null initialization of bakeStatus * TemplateUtils does not need to be a component, as it is just a superclass for concrete utils classes * Simplify the logic in removeTestsDirectoryTemplates * refactor(manifest): Update some instances of File to Path We're passing around a mix of Path and File objects; to clean up the code a bit, just standardize on Path so we don't need to interconvert between the two. * refactor(manifest): Avoid passing around a byte[] We're returning the result of a manifest bake as a byte[] because we'll eventually need to get the bytes to encode the result as base64. Instead of having doBake() return the byte[] directly, have it return a String and only convert to bytes right before encoding as base64. This reduces the number of functions that need to accept/return a byte[]. It also removes the extra conversion that needed to happen in removeTestsDirectoryTemplates. * refactor(manifest): Don't inherit artifact downloader We have a base class TemplateUtils from which both the Helm* and Kustomize* template utils inherit. The only functionality here is an artifact download function; instead of having helm and kustomize inherit from this base class, just call it ArtifactDownloader and compose it into the other utils classes. This also cleans up some of the mocking/stubbing in the utils classes (as now they can just stub the result from downloadArtifact instead of the clouddriver response) and also allows us to add some tests on the new ArtifactDownloader.
- Loading branch information
Showing
14 changed files
with
269 additions
and
158 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
rosco-manifests/src/main/java/com/netflix/spinnaker/rosco/manifests/ArtifactDownloader.java
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,25 @@ | ||
/* | ||
* Copyright 2019 Google, LLC | ||
* | ||
* 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.netflix.spinnaker.rosco.manifests; | ||
|
||
import com.netflix.spinnaker.kork.artifacts.model.Artifact; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public interface ArtifactDownloader { | ||
void downloadArtifact(Artifact artifact, Path targetFile) throws IOException; | ||
} |
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
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.