Skip to content

Commit 0783dd8

Browse files
committed
feat: extended customized columns for kubectl interaction
Signed-off-by: Jan Larwig <jan.larwig@digits.schwarz>
1 parent b8fdae0 commit 0783dd8

13 files changed

Lines changed: 136 additions & 14 deletions

‎api/v1alpha1/stackitcluster_types.go‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,12 @@ const (
230230
// +kubebuilder:resource:path=stackitclusters,shortName=stic,scope=Namespaced,categories=cluster-api
231231
// +kubebuilder:subresource:status
232232
// +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=".status.ready"
233+
// +kubebuilder:printcolumn:name="Region",type=string,JSONPath=".spec.region"
233234
// +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=".status.apiServerEndpoint.host"
234235
// +kubebuilder:printcolumn:name="Bastion IP",type=string,JSONPath=".status.bastion.publicIP"
236+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp"
237+
// +kubebuilder:printcolumn:name="Network ID",type=string,JSONPath=".spec.network.id",priority=1
238+
// +kubebuilder:printcolumn:name="Project ID",type=string,JSONPath=".spec.projectID",priority=1
235239
// +kubebuilder:storageversion
236240

237241
// StackitCluster is the Schema for the stackitclusters API.

‎api/v1alpha1/stackitclustertemplate_types.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ type StackitClusterTemplateResource struct {
4444

4545
// +kubebuilder:object:root=true
4646
// +kubebuilder:resource:path=stackitclustertemplates,shortName=stict,scope=Namespaced,categories=cluster-api
47+
// +kubebuilder:printcolumn:name="Region",type=string,JSONPath=".spec.template.spec.region"
48+
// +kubebuilder:printcolumn:name="LB Enabled",type=boolean,JSONPath=".spec.template.spec.apiServerLoadBalancer.enabled"
49+
// +kubebuilder:printcolumn:name="Bastion Enabled",type=boolean,JSONPath=".spec.template.spec.bastion.enabled"
50+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp"
51+
// +kubebuilder:printcolumn:name="Network ID",type=string,JSONPath=".spec.template.spec.network.id",priority=1
52+
// +kubebuilder:printcolumn:name="Project ID",type=string,JSONPath=".spec.template.spec.projectID",priority=1
4753
// +kubebuilder:storageversion
4854

4955
// StackitClusterTemplate is the Schema for the stackitclustertemplates API.

‎api/v1alpha1/stackitmachine_types.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ type StackitMachineStatus struct {
130130
// +optional
131131
InstanceState string `json:"instanceState,omitempty"`
132132

133+
// availabilityZone is the STACKIT availability zone where the VM was placed.
134+
// +optional
135+
AvailabilityZone string `json:"availabilityZone,omitempty"`
136+
133137
// addresses contains the IP addresses associated with the VM.
134138
// +optional
135139
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
@@ -159,6 +163,13 @@ const (
159163
// +kubebuilder:object:root=true
160164
// +kubebuilder:resource:path=stackitmachines,shortName=stim,scope=Namespaced,categories=cluster-api
161165
// +kubebuilder:subresource:status
166+
// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=".metadata.labels['cluster\\.x-k8s\\.io/cluster-name']",description="Cluster to which this resource belongs"
167+
// +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=".status.ready"
168+
// +kubebuilder:printcolumn:name="State",type=string,JSONPath=".status.instanceState",description="STACKIT server state"
169+
// +kubebuilder:printcolumn:name="Machine Type",type=string,JSONPath=".spec.machineType"
170+
// +kubebuilder:printcolumn:name="IP",type=string,JSONPath=".status.addresses[?(@.type=='InternalIP')].address"
171+
// +kubebuilder:printcolumn:name="Zone",type=string,JSONPath=".status.availabilityZone"
172+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp"
162173
// +kubebuilder:storageversion
163174

164175
// StackitMachine is the Schema for the stackitmachines API.

‎api/v1alpha1/stackitmachinetemplate_types.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ type StackitMachineTemplateResource struct {
4444

4545
// +kubebuilder:object:root=true
4646
// +kubebuilder:resource:path=stackitmachinetemplates,shortName=stimt,scope=Namespaced,categories=cluster-api
47+
// +kubebuilder:printcolumn:name="Machine Type",type=string,JSONPath=".spec.template.spec.machineType"
48+
// +kubebuilder:printcolumn:name="Image ID",type=string,JSONPath=".spec.template.spec.imageID"
49+
// +kubebuilder:printcolumn:name="Disk GiB",type=integer,JSONPath=".spec.template.spec.rootVolume.sizeGiB"
50+
// +kubebuilder:printcolumn:name="Zone",type=string,JSONPath=".spec.template.spec.availabilityZone"
51+
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp"
52+
// +kubebuilder:printcolumn:name="Network ID",type=string,JSONPath=".spec.template.spec.network.id",priority=1
4753
// +kubebuilder:storageversion
4854

4955
// StackitMachineTemplate is the Schema for the stackitmachinetemplates API.

‎cloud/fake/client.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,15 @@ func (c *Client) CreateServer(_ context.Context, input cloud.CreateServerInput)
190190
}
191191

192192
id := c.genID()
193+
zone := input.AvailabilityZone
194+
if zone == "" {
195+
zone = "eu01-1"
196+
}
193197
server := &cloud.Server{
194-
ID: id,
195-
Name: input.Name,
196-
State: "ACTIVE",
198+
ID: id,
199+
Name: input.Name,
200+
State: "ACTIVE",
201+
AvailabilityZone: zone,
197202
Addresses: []cloud.Address{
198203
{Type: "InternalIP", Address: "10.0.0.10"},
199204
},

‎cloud/sdk_client.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -962,9 +962,10 @@ func (c *SDKClient) serverFromSDK(ctx context.Context, server *iaas.Server) *Ser
962962
return nil
963963
}
964964
out := &Server{
965-
ID: server.GetId(),
966-
Name: server.GetName(),
967-
State: server.GetStatus(),
965+
ID: server.GetId(),
966+
Name: server.GetName(),
967+
State: server.GetStatus(),
968+
AvailabilityZone: server.GetAvailabilityZone(),
968969
}
969970
nics, err := c.iaasClient.DefaultAPI.ListServerNICs(ctx, c.projectID, c.region, out.ID).Execute()
970971
if err == nil {

‎cloud/types.go‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ package cloud
1515

1616
// Server describes a STACKIT compute instance in provider-neutral terms.
1717
type Server struct {
18-
ID string
19-
Name string
20-
State string
21-
ProviderID string
22-
Addresses []Address
18+
ID string
19+
Name string
20+
State string
21+
ProviderID string
22+
AvailabilityZone string
23+
Addresses []Address
2324
}
2425

2526
// Address is an IP or DNS endpoint of a Server.

‎config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclusters.yaml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,26 @@ spec:
2222
- jsonPath: .status.ready
2323
name: Ready
2424
type: boolean
25+
- jsonPath: .spec.region
26+
name: Region
27+
type: string
2528
- jsonPath: .status.apiServerEndpoint.host
2629
name: Endpoint
2730
type: string
2831
- jsonPath: .status.bastion.publicIP
2932
name: Bastion IP
3033
type: string
34+
- jsonPath: .metadata.creationTimestamp
35+
name: Age
36+
type: date
37+
- jsonPath: .spec.network.id
38+
name: Network ID
39+
priority: 1
40+
type: string
41+
- jsonPath: .spec.projectID
42+
name: Project ID
43+
priority: 1
44+
type: string
3145
name: v1alpha1
3246
schema:
3347
openAPIV3Schema:

‎config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclustertemplates.yaml‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,28 @@ spec:
1818
singular: stackitclustertemplate
1919
scope: Namespaced
2020
versions:
21-
- name: v1alpha1
21+
- additionalPrinterColumns:
22+
- jsonPath: .spec.template.spec.region
23+
name: Region
24+
type: string
25+
- jsonPath: .spec.template.spec.apiServerLoadBalancer.enabled
26+
name: LB Enabled
27+
type: boolean
28+
- jsonPath: .spec.template.spec.bastion.enabled
29+
name: Bastion Enabled
30+
type: boolean
31+
- jsonPath: .metadata.creationTimestamp
32+
name: Age
33+
type: date
34+
- jsonPath: .spec.template.spec.network.id
35+
name: Network ID
36+
priority: 1
37+
type: string
38+
- jsonPath: .spec.template.spec.projectID
39+
name: Project ID
40+
priority: 1
41+
type: string
42+
name: v1alpha1
2243
schema:
2344
openAPIV3Schema:
2445
description: StackitClusterTemplate is the Schema for the stackitclustertemplates
@@ -274,3 +295,4 @@ spec:
274295
type: object
275296
served: true
276297
storage: true
298+
subresources: {}

‎config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachines.yaml‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,31 @@ spec:
1818
singular: stackitmachine
1919
scope: Namespaced
2020
versions:
21-
- name: v1alpha1
21+
- additionalPrinterColumns:
22+
- description: Cluster to which this resource belongs
23+
jsonPath: .metadata.labels['cluster\.x-k8s\.io/cluster-name']
24+
name: Cluster
25+
type: string
26+
- jsonPath: .status.ready
27+
name: Ready
28+
type: boolean
29+
- description: STACKIT server state
30+
jsonPath: .status.instanceState
31+
name: State
32+
type: string
33+
- jsonPath: .spec.machineType
34+
name: Machine Type
35+
type: string
36+
- jsonPath: .status.addresses[?(@.type=='InternalIP')].address
37+
name: IP
38+
type: string
39+
- jsonPath: .status.availabilityZone
40+
name: Zone
41+
type: string
42+
- jsonPath: .metadata.creationTimestamp
43+
name: Age
44+
type: date
45+
name: v1alpha1
2246
schema:
2347
openAPIV3Schema:
2448
description: StackitMachine is the Schema for the stackitmachines API.
@@ -150,6 +174,10 @@ spec:
150174
- type
151175
type: object
152176
type: array
177+
availabilityZone:
178+
description: availabilityZone is the STACKIT availability zone where
179+
the VM was placed.
180+
type: string
153181
conditions:
154182
description: conditions represent the current state of the StackitMachine
155183
resource.

0 commit comments

Comments
 (0)