Skip to content

Commit

Permalink
Add LifecycleType for KPACK (#1162)
Browse files Browse the repository at this point in the history
There are presently three LifecycleTypes supported: buildpack, docker and kpack. The first two have been supported, and this PR adds support for the third. It also includes a KpackData class for the lifecycle data that the kpack lifecycle type can return.

API documentation clarifies what is allowed:

http://v3-apidocs.cloudfoundry.org/version/3.122.0/index.html#lifecycles

Includes a test which expands and deserializes the Kpack LifecycleType.

Resolves #1094

Signed-off-by: Daniel Mikusa <dmikusa@vmware.com>
  • Loading branch information
Daniel Mikusa authored Jul 27, 2022
1 parent 974a8b5 commit 7fb6fe9
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.cloudfoundry.client.v3.BuildpackData;
import org.cloudfoundry.client.v3.Checksum;
import org.cloudfoundry.client.v3.ChecksumType;
import org.cloudfoundry.client.v3.KpackData;
import org.cloudfoundry.client.v3.Lifecycle;
import org.cloudfoundry.client.v3.LifecycleType;
import org.cloudfoundry.client.v3.Link;
Expand Down Expand Up @@ -380,7 +381,7 @@ public void listDroplets() {
.as(StepVerifier::create)
.expectNext(ListPackageDropletsResponse.builder()
.pagination(Pagination.builder()
.totalResults(2)
.totalResults(3)
.totalPages(1)
.first(Link.builder()
.href("https://api.example.org/v3/packages/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50")
Expand Down Expand Up @@ -426,6 +427,44 @@ public void listDroplets() {
.method("PATCH")
.build())
.build())
.resource(DropletResource.builder()
.id("585bc3c1-3743-497d-88b0-403ad6b56d17")
.state(DropletState.STAGED)
.error(null)
.lifecycle(Lifecycle.builder()
.type(LifecycleType.KPACK)
.data(KpackData.builder()
.buildpacks("foo", "bar")
.build())
.build())
.image(null)
.executionMetadata("PRIVATE DATA HIDDEN")
.processType("redacted_message", "[PRIVATE DATA HIDDEN IN LISTS]")
.checksum(Checksum.builder()
.type(ChecksumType.SHA256)
.value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
.build())
.buildpack(Buildpack.builder()
.name("ruby_buildpack")
.detectOutput("ruby 1.6.14")
.build())
.stack("cflinuxfs2")
.createdAt("2016-03-28T23:39:34Z")
.updatedAt("2016-03-28T23:39:47Z")
.link("self", Link.builder()
.href("https://api.example.org/v3/droplets/585bc3c1-3743-497d-88b0-403ad6b56d17")
.build())
.link("package", Link.builder()
.href("https://api.example.org/v3/packages/8222f76a-9e09-4360-b3aa-1ed329945e93")
.build())
.link("app", Link.builder()
.href("https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397")
.build())
.link("assign_current_droplet", Link.builder()
.href("https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397/relationships/current_droplet")
.method("PATCH")
.build())
.build())
.resource(DropletResource.builder()
.id("fdf3851c-def8-4de1-87f1-6d4543189e22")
.state(DropletState.STAGED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pagination": {
"total_results": 2,
"total_results": 3,
"total_pages": 1,
"first": {
"href": "https://api.example.org/v3/packages/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50"
Expand Down Expand Up @@ -54,6 +54,50 @@
}
}
},
{
"guid": "585bc3c1-3743-497d-88b0-403ad6b56d17",
"state": "STAGED",
"error": null,
"lifecycle": {
"type": "kpack",
"data": {
"buildpacks": ["foo", "bar"]
}
},
"image": null,
"execution_metadata": "PRIVATE DATA HIDDEN",
"process_types": {
"redacted_message": "[PRIVATE DATA HIDDEN IN LISTS]"
},
"checksum": {
"type": "sha256",
"value": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
"buildpacks": [
{
"name": "ruby_buildpack",
"detect_output": "ruby 1.6.14"
}
],
"stack": "cflinuxfs2",
"created_at": "2016-03-28T23:39:34Z",
"updated_at": "2016-03-28T23:39:47Z",
"links": {
"self": {
"href": "https://api.example.org/v3/droplets/585bc3c1-3743-497d-88b0-403ad6b56d17"
},
"package": {
"href": "https://api.example.org/v3/packages/8222f76a-9e09-4360-b3aa-1ed329945e93"
},
"app": {
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397"
},
"assign_current_droplet": {
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397/relationships/current_droplet",
"method": "PATCH"
}
}
},
{
"guid": "fdf3851c-def8-4de1-87f1-6d4543189e22",
"state": "STAGED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public enum LifecycleType {

BUILDPACK("buildpack"),

DOCKER("docker");
DOCKER("docker"),

KPACK( "kpack");

private final String value;

Expand All @@ -38,6 +40,8 @@ public static LifecycleType from(String s) {
return BUILDPACK;
case "docker":
return DOCKER;
case "kpack":
return KPACK;
default:
throw new IllegalArgumentException(String.format("Unknown lifecycle type: %s", s));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* 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 org.cloudfoundry.client.v3;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.cloudfoundry.Nullable;
import org.immutables.value.Value;

import java.util.List;

/**
* Data type for the Kpack
*/
@JsonDeserialize
@Value.Immutable
abstract class _KpackData implements LifecycleData {

/**
* The buildpack
*/
@JsonProperty("buildpacks")
@Nullable
abstract List<String> getBuildpacks();

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ abstract class _Lifecycle {
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(name = "buildpack", value = BuildpackData.class),
@JsonSubTypes.Type(name = "docker", value = DockerData.class)
@JsonSubTypes.Type(name = "docker", value = DockerData.class),
@JsonSubTypes.Type(name = "kpack", value = KpackData.class)
})
@JsonProperty("data")
abstract LifecycleData getData();
Expand Down

0 comments on commit 7fb6fe9

Please sign in to comment.