Skip to content

Commit 7fb6fe9

Browse files
author
Daniel Mikusa
authored
Add LifecycleType for KPACK (#1162)
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 <[email protected]>
1 parent 974a8b5 commit 7fb6fe9

File tree

5 files changed

+132
-4
lines changed

5 files changed

+132
-4
lines changed

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/packages/ReactorPackagesTest.java

+40-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.cloudfoundry.client.v3.BuildpackData;
2020
import org.cloudfoundry.client.v3.Checksum;
2121
import org.cloudfoundry.client.v3.ChecksumType;
22+
import org.cloudfoundry.client.v3.KpackData;
2223
import org.cloudfoundry.client.v3.Lifecycle;
2324
import org.cloudfoundry.client.v3.LifecycleType;
2425
import org.cloudfoundry.client.v3.Link;
@@ -380,7 +381,7 @@ public void listDroplets() {
380381
.as(StepVerifier::create)
381382
.expectNext(ListPackageDropletsResponse.builder()
382383
.pagination(Pagination.builder()
383-
.totalResults(2)
384+
.totalResults(3)
384385
.totalPages(1)
385386
.first(Link.builder()
386387
.href("https://api.example.org/v3/packages/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50")
@@ -426,6 +427,44 @@ public void listDroplets() {
426427
.method("PATCH")
427428
.build())
428429
.build())
430+
.resource(DropletResource.builder()
431+
.id("585bc3c1-3743-497d-88b0-403ad6b56d17")
432+
.state(DropletState.STAGED)
433+
.error(null)
434+
.lifecycle(Lifecycle.builder()
435+
.type(LifecycleType.KPACK)
436+
.data(KpackData.builder()
437+
.buildpacks("foo", "bar")
438+
.build())
439+
.build())
440+
.image(null)
441+
.executionMetadata("PRIVATE DATA HIDDEN")
442+
.processType("redacted_message", "[PRIVATE DATA HIDDEN IN LISTS]")
443+
.checksum(Checksum.builder()
444+
.type(ChecksumType.SHA256)
445+
.value("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
446+
.build())
447+
.buildpack(Buildpack.builder()
448+
.name("ruby_buildpack")
449+
.detectOutput("ruby 1.6.14")
450+
.build())
451+
.stack("cflinuxfs2")
452+
.createdAt("2016-03-28T23:39:34Z")
453+
.updatedAt("2016-03-28T23:39:47Z")
454+
.link("self", Link.builder()
455+
.href("https://api.example.org/v3/droplets/585bc3c1-3743-497d-88b0-403ad6b56d17")
456+
.build())
457+
.link("package", Link.builder()
458+
.href("https://api.example.org/v3/packages/8222f76a-9e09-4360-b3aa-1ed329945e93")
459+
.build())
460+
.link("app", Link.builder()
461+
.href("https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397")
462+
.build())
463+
.link("assign_current_droplet", Link.builder()
464+
.href("https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397/relationships/current_droplet")
465+
.method("PATCH")
466+
.build())
467+
.build())
429468
.resource(DropletResource.builder()
430469
.id("fdf3851c-def8-4de1-87f1-6d4543189e22")
431470
.state(DropletState.STAGED)

cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/packages/GET_{id}_droplets_response.json

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"pagination": {
3-
"total_results": 2,
3+
"total_results": 3,
44
"total_pages": 1,
55
"first": {
66
"href": "https://api.example.org/v3/packages/7b34f1cf-7e73-428a-bb5a-8a17a8058396/droplets?page=1&per_page=50"
@@ -54,6 +54,50 @@
5454
}
5555
}
5656
},
57+
{
58+
"guid": "585bc3c1-3743-497d-88b0-403ad6b56d17",
59+
"state": "STAGED",
60+
"error": null,
61+
"lifecycle": {
62+
"type": "kpack",
63+
"data": {
64+
"buildpacks": ["foo", "bar"]
65+
}
66+
},
67+
"image": null,
68+
"execution_metadata": "PRIVATE DATA HIDDEN",
69+
"process_types": {
70+
"redacted_message": "[PRIVATE DATA HIDDEN IN LISTS]"
71+
},
72+
"checksum": {
73+
"type": "sha256",
74+
"value": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
75+
},
76+
"buildpacks": [
77+
{
78+
"name": "ruby_buildpack",
79+
"detect_output": "ruby 1.6.14"
80+
}
81+
],
82+
"stack": "cflinuxfs2",
83+
"created_at": "2016-03-28T23:39:34Z",
84+
"updated_at": "2016-03-28T23:39:47Z",
85+
"links": {
86+
"self": {
87+
"href": "https://api.example.org/v3/droplets/585bc3c1-3743-497d-88b0-403ad6b56d17"
88+
},
89+
"package": {
90+
"href": "https://api.example.org/v3/packages/8222f76a-9e09-4360-b3aa-1ed329945e93"
91+
},
92+
"app": {
93+
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397"
94+
},
95+
"assign_current_droplet": {
96+
"href": "https://api.example.org/v3/apps/7b34f1cf-7e73-428a-bb5a-8a17a8058397/relationships/current_droplet",
97+
"method": "PATCH"
98+
}
99+
}
100+
},
57101
{
58102
"guid": "fdf3851c-def8-4de1-87f1-6d4543189e22",
59103
"state": "STAGED",

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/LifecycleType.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public enum LifecycleType {
2323

2424
BUILDPACK("buildpack"),
2525

26-
DOCKER("docker");
26+
DOCKER("docker"),
27+
28+
KPACK( "kpack");
2729

2830
private final String value;
2931

@@ -38,6 +40,8 @@ public static LifecycleType from(String s) {
3840
return BUILDPACK;
3941
case "docker":
4042
return DOCKER;
43+
case "kpack":
44+
return KPACK;
4145
default:
4246
throw new IllegalArgumentException(String.format("Unknown lifecycle type: %s", s));
4347
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2013-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.cloudfoundry.client.v3;
18+
19+
import com.fasterxml.jackson.annotation.JsonProperty;
20+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
21+
import org.cloudfoundry.Nullable;
22+
import org.immutables.value.Value;
23+
24+
import java.util.List;
25+
26+
/**
27+
* Data type for the Kpack
28+
*/
29+
@JsonDeserialize
30+
@Value.Immutable
31+
abstract class _KpackData implements LifecycleData {
32+
33+
/**
34+
* The buildpack
35+
*/
36+
@JsonProperty("buildpacks")
37+
@Nullable
38+
abstract List<String> getBuildpacks();
39+
40+
}

cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/_Lifecycle.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ abstract class _Lifecycle {
3535
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "type")
3636
@JsonSubTypes({
3737
@JsonSubTypes.Type(name = "buildpack", value = BuildpackData.class),
38-
@JsonSubTypes.Type(name = "docker", value = DockerData.class)
38+
@JsonSubTypes.Type(name = "docker", value = DockerData.class),
39+
@JsonSubTypes.Type(name = "kpack", value = KpackData.class)
3940
})
4041
@JsonProperty("data")
4142
abstract LifecycleData getData();

0 commit comments

Comments
 (0)