Skip to content

Commit 34aa5ab

Browse files
georgethebeatledanail-branekov
authored andcommitted
Test for additionalPrinterColumns used for ordering
- As we are using additionalPrinterColumns and the "get as table" feature of kubeapiserver we have to make sure that the table fields that we use for ordering are there and stay there. - This changes adds tests for all ordering fields of all currently implementd v3 resouces in Korifi as per the v3 spec - Some of the newly added fields are not yet used for ordering - Some existing fields were changed, minly display names - The "state" field of the cfapp resource is changed to desired state, because this is how it is defined in the spec issue #3701
1 parent fd7c553 commit 34aa5ab

19 files changed

+287
-10
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
package descriptors_test
2+
3+
import (
4+
"fmt"
5+
"maps"
6+
"slices"
7+
8+
korifiv1alpha1 "code.cloudfoundry.org/korifi/controllers/api/v1alpha1"
9+
"code.cloudfoundry.org/korifi/tools"
10+
"github.com/BooleanCat/go-functional/v2/it"
11+
"github.com/google/uuid"
12+
. "github.com/onsi/ginkgo/v2"
13+
. "github.com/onsi/gomega"
14+
corev1 "k8s.io/api/core/v1"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"sigs.k8s.io/controller-runtime/pkg/client"
17+
18+
. "github.com/onsi/gomega/gstruct"
19+
"github.com/onsi/gomega/types"
20+
)
21+
22+
var _ = DescribeTable("Table Columns For Ordering", testTableColumns,
23+
Entry("CFApps", "cfapps", &korifiv1alpha1.CFApp{
24+
Spec: korifiv1alpha1.CFAppSpec{
25+
DisplayName: "cfapp",
26+
DesiredState: "STOPPED",
27+
Lifecycle: korifiv1alpha1.Lifecycle{
28+
Type: "buildpack",
29+
},
30+
},
31+
}, MatchKeys(IgnoreExtras, Keys{
32+
"Created At": Equal("obj-creation-timestamp"),
33+
"Updated At": Equal("obj-update-timestamp"),
34+
"Display Name": Equal("cfapp"),
35+
"State": Equal("STOPPED"),
36+
})),
37+
38+
Entry("CFBuild", "cfbuilds", &korifiv1alpha1.CFBuild{
39+
Spec: korifiv1alpha1.CFBuildSpec{
40+
Lifecycle: korifiv1alpha1.Lifecycle{
41+
Type: "buildpack",
42+
},
43+
},
44+
}, MatchKeys(IgnoreExtras, Keys{
45+
"Created At": Equal("obj-creation-timestamp"),
46+
"Updated At": Equal("obj-update-timestamp"),
47+
})),
48+
49+
Entry("CFDomain", "cfdomains", &korifiv1alpha1.CFDomain{
50+
Spec: korifiv1alpha1.CFDomainSpec{
51+
Name: "example.com",
52+
},
53+
}, MatchKeys(IgnoreExtras, Keys{
54+
"Created At": Equal("obj-creation-timestamp"),
55+
"Updated At": Equal("obj-update-timestamp"),
56+
})),
57+
58+
Entry("CFOrg", "cforgs", &korifiv1alpha1.CFOrg{
59+
Spec: korifiv1alpha1.CFOrgSpec{
60+
DisplayName: "example-org",
61+
},
62+
}, MatchKeys(IgnoreExtras, Keys{
63+
"Created At": Equal("obj-creation-timestamp"),
64+
"Updated At": Equal("obj-update-timestamp"),
65+
"Display Name": Equal("example-org"),
66+
})),
67+
68+
Entry("CFPackage", "cfpackages", &korifiv1alpha1.CFPackage{
69+
Spec: korifiv1alpha1.CFPackageSpec{
70+
Type: "bits",
71+
},
72+
}, MatchKeys(IgnoreExtras, Keys{
73+
"Created At": Equal("obj-creation-timestamp"),
74+
"Updated At": Equal("obj-update-timestamp"),
75+
})),
76+
77+
Entry("CFProcess", "cfprocesses", &korifiv1alpha1.CFProcess{}, MatchKeys(IgnoreExtras, Keys{
78+
"Created At": Equal("obj-creation-timestamp"),
79+
"Updated At": Equal("obj-update-timestamp"),
80+
})),
81+
82+
Entry("CFRoute", "cfroutes", &korifiv1alpha1.CFRoute{
83+
Spec: korifiv1alpha1.CFRouteSpec{
84+
Host: "example",
85+
Path: "/example",
86+
DomainRef: corev1.ObjectReference{
87+
Name: "example.com",
88+
},
89+
},
90+
}, MatchKeys(IgnoreExtras, Keys{
91+
"Created At": Equal("obj-creation-timestamp"),
92+
"Updated At": Equal("obj-update-timestamp"),
93+
})),
94+
95+
Entry("CFSecurityGroup", "cfsecuritygroups", &korifiv1alpha1.CFSecurityGroup{
96+
Spec: korifiv1alpha1.CFSecurityGroupSpec{
97+
Rules: []korifiv1alpha1.SecurityGroupRule{},
98+
},
99+
}, MatchKeys(IgnoreExtras, Keys{
100+
"Created At": Equal("obj-creation-timestamp"),
101+
"Updated At": Equal("obj-update-timestamp"),
102+
})),
103+
104+
Entry("CFServiceBinding", "cfservicebindings", &korifiv1alpha1.CFServiceBinding{
105+
Spec: korifiv1alpha1.CFServiceBindingSpec{
106+
DisplayName: tools.PtrTo("example-binding"),
107+
Type: "key",
108+
},
109+
}, MatchKeys(IgnoreExtras, Keys{
110+
"Created At": Equal("obj-creation-timestamp"),
111+
"Updated At": Equal("obj-update-timestamp"),
112+
"Display Name": Equal("example-binding"),
113+
})),
114+
115+
Entry("CFServiceBroker", "cfservicebrokers", &korifiv1alpha1.CFServiceBroker{
116+
Spec: korifiv1alpha1.CFServiceBrokerSpec{
117+
Name: "example-broker",
118+
},
119+
}, MatchKeys(IgnoreExtras, Keys{
120+
"Created At": Equal("obj-creation-timestamp"),
121+
"Updated At": Equal("obj-update-timestamp"),
122+
"Display Name": Equal("example-broker"),
123+
})),
124+
125+
Entry("CFServiceInstance", "cfserviceinstances", &korifiv1alpha1.CFServiceInstance{
126+
Spec: korifiv1alpha1.CFServiceInstanceSpec{
127+
DisplayName: "example-instance",
128+
Type: "user-provided",
129+
},
130+
}, MatchKeys(IgnoreExtras, Keys{
131+
"Created At": Equal("obj-creation-timestamp"),
132+
"Updated At": Equal("obj-update-timestamp"),
133+
"Display Name": Equal("example-instance"),
134+
})),
135+
136+
Entry("CFServiceOffering", "cfserviceofferings", &korifiv1alpha1.CFServiceOffering{
137+
Spec: korifiv1alpha1.CFServiceOfferingSpec{
138+
Name: "example-offering",
139+
},
140+
}, MatchKeys(IgnoreExtras, Keys{
141+
"Created At": Equal("obj-creation-timestamp"),
142+
"Updated At": Equal("obj-update-timestamp"),
143+
"Display Name": Equal("example-offering"),
144+
})),
145+
146+
Entry("CFServicePlan", "cfserviceplans", &korifiv1alpha1.CFServicePlan{
147+
Spec: korifiv1alpha1.CFServicePlanSpec{
148+
Name: "example-plan",
149+
Visibility: korifiv1alpha1.ServicePlanVisibility{
150+
Type: korifiv1alpha1.PublicServicePlanVisibilityType,
151+
},
152+
},
153+
}, MatchKeys(IgnoreExtras, Keys{
154+
"Created At": Equal("obj-creation-timestamp"),
155+
"Updated At": Equal("obj-update-timestamp"),
156+
"Display Name": Equal("example-plan"),
157+
})),
158+
159+
Entry("CFSpace", "cfspaces", &korifiv1alpha1.CFSpace{
160+
Spec: korifiv1alpha1.CFSpaceSpec{
161+
DisplayName: "example-space",
162+
},
163+
}, MatchKeys(IgnoreExtras, Keys{
164+
"Created At": Equal("obj-creation-timestamp"),
165+
"Updated At": Equal("obj-update-timestamp"),
166+
"Display Name": Equal("example-space"),
167+
})),
168+
169+
Entry("CFTask", "cftasks", &korifiv1alpha1.CFTask{}, MatchKeys(IgnoreExtras, Keys{
170+
"Created At": Equal("obj-creation-timestamp"),
171+
"Updated At": Equal("obj-update-timestamp"),
172+
})),
173+
)
174+
175+
func testTableColumns(resourceType string, obj client.Object, match types.GomegaMatcher) {
176+
namespace := uuid.NewString()
177+
Expect(k8sClient.Create(ctx, &corev1.Namespace{
178+
ObjectMeta: metav1.ObjectMeta{
179+
Name: namespace,
180+
},
181+
})).To(Succeed())
182+
183+
obj.SetName(uuid.NewString())
184+
obj.SetNamespace(namespace)
185+
obj.SetLabels(map[string]string{
186+
korifiv1alpha1.CreatedAtLabelKey: "obj-creation-timestamp",
187+
korifiv1alpha1.UpdatedAtLabelKey: "obj-update-timestamp",
188+
})
189+
Expect(k8sClient.Create(ctx, obj)).To(Succeed())
190+
191+
table := &metav1.Table{}
192+
Expect(restClient.Get().
193+
AbsPath(fmt.Sprintf("/apis/korifi.cloudfoundry.org/v1alpha1/namespaces/%s/%s", namespace, resourceType)).
194+
SetHeader("Accept", "application/json;as=Table;g=meta.k8s.io;v=v1").
195+
Do(ctx).
196+
Into(table),
197+
).To(Succeed())
198+
199+
Expect(columnNameValues(table)).To(match)
200+
}
201+
202+
func columnNameValues(table *metav1.Table) map[string]any {
203+
GinkgoHelper()
204+
205+
columnsNames := it.Map(slices.Values(table.ColumnDefinitions), func(column metav1.TableColumnDefinition) string {
206+
return column.Name
207+
})
208+
Expect(table.Rows).To(HaveLen(1))
209+
firstRowCells := slices.Values(table.Rows[0].Cells)
210+
return maps.Collect(it.Zip(columnsNames, firstRowCells))
211+
}

controllers/api/v1alpha1/cfapp_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type CFAppStatus struct {
8888
//+kubebuilder:printcolumn:name="Display Name",type=string,JSONPath=`.spec.displayName`
8989
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
9090
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
91-
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.status.actualState`
91+
//+kubebuilder:printcolumn:name="State",type=string,JSONPath=`.spec.desiredState`
9292
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`
9393
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
9494

controllers/api/v1alpha1/cforg_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type CFOrgStatus struct {
5050

5151
//+kubebuilder:object:root=true
5252
//+kubebuilder:subresource:status
53+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
54+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
5355
//+kubebuilder:printcolumn:name="Display Name",type=string,JSONPath=`.spec.displayName`
5456
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`
5557
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

controllers/api/v1alpha1/cfprocess_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type CFProcessStatus struct {
9797

9898
//+kubebuilder:object:root=true
9999
//+kubebuilder:subresource:status
100+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
101+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
100102
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
101103

102104
// CFProcess is the Schema for the cfprocesses API

controllers/api/v1alpha1/cfsecuritygroup_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type CFSecurityGroupStatus struct {
4646

4747
//+kubebuilder:subresource:status
4848
//+kubebuilder:object:root=true
49+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
50+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
4951
//+kubebuilder:printcolumn:name="DisplayName",type=string,JSONPath=`.spec.displayName`
5052
//+k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
5153

controllers/api/v1alpha1/cfservice_offering_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ type BrokerCatalogFeatures struct {
3636
}
3737

3838
//+kubebuilder:object:root=true
39-
//+kubebuilder:printcolumn:name="Offering",type=string,JSONPath=`.spec.name`
39+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
40+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
41+
//+kubebuilder:printcolumn:name="Display Name",type=string,JSONPath=`.spec.name`
4042
//+kubebuilder:printcolumn:name="Description",type=string,JSONPath=`.spec.description`
4143
//+kubebuilder:printcolumn:name="Available",type=string,JSONPath=`.spec.available`
4244
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`

controllers/api/v1alpha1/cfservice_plan_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ type ServicePlanVisibility struct {
7575
}
7676

7777
// +kubebuilder:object:root=true
78-
// +kubebuilder:printcolumn:name="Plan",type=string,JSONPath=`.spec.name`
78+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
79+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
80+
// +kubebuilder:printcolumn:name="Display Name",type=string,JSONPath=`.spec.name`
7981
// +kubebuilder:printcolumn:name="Available",type=string,JSONPath=`.spec.available`
8082
// +kubebuilder:printcolumn:name="Free",type=string,JSONPath=`.spec.free`
8183
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`

controllers/api/v1alpha1/cfservicebroker_types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ type CFServiceBrokerStatus struct {
3535

3636
// +kubebuilder:object:root=true
3737
// +kubebuilder:subresource:status
38-
// +kubebuilder:printcolumn:name="Broker Name",type=string,JSONPath=`.spec.name`
38+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
39+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
40+
// +kubebuilder:printcolumn:name="Display Name",type=string,JSONPath=`.spec.name`
3941
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`
4042
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
4143

controllers/api/v1alpha1/cfspace_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ type CFSpaceStatus struct {
5050

5151
//+kubebuilder:object:root=true
5252
//+kubebuilder:subresource:status
53+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
54+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
5355
//+kubebuilder:printcolumn:name="Display Name",type=string,JSONPath=`.spec.displayName`
5456
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=`.metadata.creationTimestamp`
5557
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

controllers/api/v1alpha1/cftask_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ type CFTaskStatus struct {
6161

6262
//+kubebuilder:object:root=true
6363
//+kubebuilder:subresource:status
64+
//+kubebuilder:printcolumn:name="Created At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/created_at`
65+
//+kubebuilder:printcolumn:name="Updated At",type="string",JSONPath=`.metadata.labels.korifi\.cloudfoundry\.org/updated_at`
6466
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
6567

6668
// CFTask is the Schema for the cftasks API

0 commit comments

Comments
 (0)