Skip to content

Commit

Permalink
feat(provider/kubernetes): cleanup artifacts task
Browse files Browse the repository at this point in the history
Required to remove artifacts above max-version-history
  • Loading branch information
Lars Wander committed Jun 4, 2018
1 parent 3d2e9ce commit 74a0104
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
package com.netflix.spinnaker.orca.clouddriver.pipeline.manifest;

import com.netflix.spinnaker.orca.clouddriver.tasks.MonitorKatoTask;
import com.netflix.spinnaker.orca.pipeline.tasks.artifacts.BindProducedArtifactsTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.artifacts.CleanupArtifactsTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.DeployManifestTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.ManifestForceCacheRefreshTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.PromoteManifestKatoOutputsTask;
import com.netflix.spinnaker.orca.clouddriver.tasks.manifest.WaitForManifestStableTask;
import com.netflix.spinnaker.orca.pipeline.StageDefinitionBuilder;
import com.netflix.spinnaker.orca.pipeline.TaskNode;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import com.netflix.spinnaker.orca.pipeline.tasks.artifacts.BindProducedArtifactsTask;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -39,6 +40,7 @@ public void taskGraph(Stage stage, TaskNode.Builder builder) {
.withTask(PromoteManifestKatoOutputsTask.TASK_NAME, PromoteManifestKatoOutputsTask.class)
.withTask(ManifestForceCacheRefreshTask.TASK_NAME, ManifestForceCacheRefreshTask.class)
.withTask(WaitForManifestStableTask.TASK_NAME, WaitForManifestStableTask.class)
.withTask(CleanupArtifactsTask.TASK_NAME, CleanupArtifactsTask.class)
.withTask(BindProducedArtifactsTask.TASK_NAME, BindProducedArtifactsTask.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2018 Google, Inc.
*
* 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.orca.clouddriver.tasks.artifacts;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import com.netflix.spinnaker.orca.ExecutionStatus;
import com.netflix.spinnaker.orca.Task;
import com.netflix.spinnaker.orca.TaskResult;
import com.netflix.spinnaker.orca.clouddriver.KatoService;
import com.netflix.spinnaker.orca.clouddriver.model.TaskId;
import com.netflix.spinnaker.orca.clouddriver.tasks.AbstractCloudProviderAwareTask;
import com.netflix.spinnaker.orca.pipeline.model.Stage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.Map;

@Component
public class CleanupArtifactsTask extends AbstractCloudProviderAwareTask implements Task {
public static final String TASK_NAME = "cleanupArtifacts";

@Autowired
KatoService kato;

@Autowired
ObjectMapper objectMapper;

@Nonnull
@Override
public TaskResult execute(@Nonnull Stage stage) {
Map<String, Object> context = stage.getContext();
String credentials = getCredentials(stage);
String cloudProvider = getCloudProvider(stage);

Map<String, Object> task = new ImmutableMap.Builder<String, Object>()
.put("manifests", context.get("outputs.manifests"))
.put("account", credentials)
.build();

Map<String, Map> operation = new ImmutableMap.Builder<String, Map>()
.put(TASK_NAME, task)
.build();

TaskId taskId = kato.requestOperations(cloudProvider, Collections.singletonList(operation)).toBlocking().first();

Map<String, Object> outputs = new ImmutableMap.Builder<String, Object>()
.put("kato.result.expected", false)
.put("kato.last.task.id", taskId)
.put("deploy.account.name", credentials)
.build();

return new TaskResult(ExecutionStatus.SUCCEEDED, outputs);
}
}

0 comments on commit 74a0104

Please sign in to comment.