diff --git a/api/v1alpha1/stackitcluster_types.go b/api/v1alpha1/stackitcluster_types.go index cd431a5..413452e 100644 --- a/api/v1alpha1/stackitcluster_types.go +++ b/api/v1alpha1/stackitcluster_types.go @@ -230,8 +230,12 @@ const ( // +kubebuilder:resource:path=stackitclusters,shortName=stic,scope=Namespaced,categories=cluster-api // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=".status.ready" +// +kubebuilder:printcolumn:name="Region",type=string,JSONPath=".spec.region" // +kubebuilder:printcolumn:name="Endpoint",type=string,JSONPath=".status.apiServerEndpoint.host" // +kubebuilder:printcolumn:name="Bastion IP",type=string,JSONPath=".status.bastion.publicIP" +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp" +// +kubebuilder:printcolumn:name="Network ID",type=string,JSONPath=".spec.network.id",priority=1 +// +kubebuilder:printcolumn:name="Project ID",type=string,JSONPath=".spec.projectID",priority=1 // +kubebuilder:storageversion // StackitCluster is the Schema for the stackitclusters API. diff --git a/api/v1alpha1/stackitclustertemplate_types.go b/api/v1alpha1/stackitclustertemplate_types.go index 1f79b55..a37e55c 100644 --- a/api/v1alpha1/stackitclustertemplate_types.go +++ b/api/v1alpha1/stackitclustertemplate_types.go @@ -44,6 +44,12 @@ type StackitClusterTemplateResource struct { // +kubebuilder:object:root=true // +kubebuilder:resource:path=stackitclustertemplates,shortName=stict,scope=Namespaced,categories=cluster-api +// +kubebuilder:printcolumn:name="Region",type=string,JSONPath=".spec.template.spec.region" +// +kubebuilder:printcolumn:name="LB Enabled",type=boolean,JSONPath=".spec.template.spec.apiServerLoadBalancer.enabled" +// +kubebuilder:printcolumn:name="Bastion Enabled",type=boolean,JSONPath=".spec.template.spec.bastion.enabled" +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp" +// +kubebuilder:printcolumn:name="Network ID",type=string,JSONPath=".spec.template.spec.network.id",priority=1 +// +kubebuilder:printcolumn:name="Project ID",type=string,JSONPath=".spec.template.spec.projectID",priority=1 // +kubebuilder:storageversion // StackitClusterTemplate is the Schema for the stackitclustertemplates API. diff --git a/api/v1alpha1/stackitmachine_types.go b/api/v1alpha1/stackitmachine_types.go index 6d71fc8..208e77e 100644 --- a/api/v1alpha1/stackitmachine_types.go +++ b/api/v1alpha1/stackitmachine_types.go @@ -130,6 +130,10 @@ type StackitMachineStatus struct { // +optional InstanceState string `json:"instanceState,omitempty"` + // availabilityZone is the STACKIT availability zone where the VM was placed. + // +optional + AvailabilityZone string `json:"availabilityZone,omitempty"` + // addresses contains the IP addresses associated with the VM. // +optional Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"` @@ -159,6 +163,13 @@ const ( // +kubebuilder:object:root=true // +kubebuilder:resource:path=stackitmachines,shortName=stim,scope=Namespaced,categories=cluster-api // +kubebuilder:subresource:status +// +kubebuilder:printcolumn:name="Cluster",type=string,JSONPath=".metadata.labels['cluster\\.x-k8s\\.io/cluster-name']",description="Cluster to which this resource belongs" +// +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=".status.ready" +// +kubebuilder:printcolumn:name="State",type=string,JSONPath=".status.instanceState",description="STACKIT server state" +// +kubebuilder:printcolumn:name="Machine Type",type=string,JSONPath=".spec.machineType" +// +kubebuilder:printcolumn:name="IP",type=string,JSONPath=".status.addresses[?(@.type=='InternalIP')].address" +// +kubebuilder:printcolumn:name="Zone",type=string,JSONPath=".status.availabilityZone" +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp" // +kubebuilder:storageversion // StackitMachine is the Schema for the stackitmachines API. diff --git a/api/v1alpha1/stackitmachinetemplate_types.go b/api/v1alpha1/stackitmachinetemplate_types.go index 5121887..e3f00dd 100644 --- a/api/v1alpha1/stackitmachinetemplate_types.go +++ b/api/v1alpha1/stackitmachinetemplate_types.go @@ -44,6 +44,12 @@ type StackitMachineTemplateResource struct { // +kubebuilder:object:root=true // +kubebuilder:resource:path=stackitmachinetemplates,shortName=stimt,scope=Namespaced,categories=cluster-api +// +kubebuilder:printcolumn:name="Machine Type",type=string,JSONPath=".spec.template.spec.machineType" +// +kubebuilder:printcolumn:name="Image ID",type=string,JSONPath=".spec.template.spec.imageID" +// +kubebuilder:printcolumn:name="Disk GiB",type=integer,JSONPath=".spec.template.spec.rootVolume.sizeGiB" +// +kubebuilder:printcolumn:name="Zone",type=string,JSONPath=".spec.template.spec.availabilityZone" +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=".metadata.creationTimestamp" +// +kubebuilder:printcolumn:name="Network ID",type=string,JSONPath=".spec.template.spec.network.id",priority=1 // +kubebuilder:storageversion // StackitMachineTemplate is the Schema for the stackitmachinetemplates API. diff --git a/cloud/fake/client.go b/cloud/fake/client.go index 0642e49..43fe048 100644 --- a/cloud/fake/client.go +++ b/cloud/fake/client.go @@ -190,10 +190,15 @@ func (c *Client) CreateServer(_ context.Context, input cloud.CreateServerInput) } id := c.genID() + zone := input.AvailabilityZone + if zone == "" { + zone = "eu01-1" + } server := &cloud.Server{ - ID: id, - Name: input.Name, - State: "ACTIVE", + ID: id, + Name: input.Name, + State: "ACTIVE", + AvailabilityZone: zone, Addresses: []cloud.Address{ {Type: "InternalIP", Address: "10.0.0.10"}, }, diff --git a/cloud/sdk_client.go b/cloud/sdk_client.go index fc02cb2..fd2b21f 100644 --- a/cloud/sdk_client.go +++ b/cloud/sdk_client.go @@ -962,9 +962,10 @@ func (c *SDKClient) serverFromSDK(ctx context.Context, server *iaas.Server) *Ser return nil } out := &Server{ - ID: server.GetId(), - Name: server.GetName(), - State: server.GetStatus(), + ID: server.GetId(), + Name: server.GetName(), + State: server.GetStatus(), + AvailabilityZone: server.GetAvailabilityZone(), } nics, err := c.iaasClient.DefaultAPI.ListServerNICs(ctx, c.projectID, c.region, out.ID).Execute() if err == nil { diff --git a/cloud/types.go b/cloud/types.go index ddc5d6d..065ee82 100644 --- a/cloud/types.go +++ b/cloud/types.go @@ -15,11 +15,12 @@ package cloud // Server describes a STACKIT compute instance in provider-neutral terms. type Server struct { - ID string - Name string - State string - ProviderID string - Addresses []Address + ID string + Name string + State string + ProviderID string + AvailabilityZone string + Addresses []Address } // Address is an IP or DNS endpoint of a Server. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclusters.yaml index 563a9c3..ac12a64 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclusters.yaml @@ -22,12 +22,26 @@ spec: - jsonPath: .status.ready name: Ready type: boolean + - jsonPath: .spec.region + name: Region + type: string - jsonPath: .status.apiServerEndpoint.host name: Endpoint type: string - jsonPath: .status.bastion.publicIP name: Bastion IP type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + - jsonPath: .spec.network.id + name: Network ID + priority: 1 + type: string + - jsonPath: .spec.projectID + name: Project ID + priority: 1 + type: string name: v1alpha1 schema: openAPIV3Schema: diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclustertemplates.yaml index fccf534..202fe16 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitclustertemplates.yaml @@ -18,7 +18,28 @@ spec: singular: stackitclustertemplate scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - jsonPath: .spec.template.spec.region + name: Region + type: string + - jsonPath: .spec.template.spec.apiServerLoadBalancer.enabled + name: LB Enabled + type: boolean + - jsonPath: .spec.template.spec.bastion.enabled + name: Bastion Enabled + type: boolean + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + - jsonPath: .spec.template.spec.network.id + name: Network ID + priority: 1 + type: string + - jsonPath: .spec.template.spec.projectID + name: Project ID + priority: 1 + type: string + name: v1alpha1 schema: openAPIV3Schema: description: StackitClusterTemplate is the Schema for the stackitclustertemplates @@ -274,3 +295,4 @@ spec: type: object served: true storage: true + subresources: {} diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachines.yaml index f8c4814..ae3aa81 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachines.yaml @@ -18,7 +18,31 @@ spec: singular: stackitmachine scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - description: Cluster to which this resource belongs + jsonPath: .metadata.labels['cluster\.x-k8s\.io/cluster-name'] + name: Cluster + type: string + - jsonPath: .status.ready + name: Ready + type: boolean + - description: STACKIT server state + jsonPath: .status.instanceState + name: State + type: string + - jsonPath: .spec.machineType + name: Machine Type + type: string + - jsonPath: .status.addresses[?(@.type=='InternalIP')].address + name: IP + type: string + - jsonPath: .status.availabilityZone + name: Zone + type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha1 schema: openAPIV3Schema: description: StackitMachine is the Schema for the stackitmachines API. @@ -150,6 +174,10 @@ spec: - type type: object type: array + availabilityZone: + description: availabilityZone is the STACKIT availability zone where + the VM was placed. + type: string conditions: description: conditions represent the current state of the StackitMachine resource. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachinetemplates.yaml index c5b23a1..b09022b 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_stackitmachinetemplates.yaml @@ -18,7 +18,27 @@ spec: singular: stackitmachinetemplate scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - jsonPath: .spec.template.spec.machineType + name: Machine Type + type: string + - jsonPath: .spec.template.spec.imageID + name: Image ID + type: string + - jsonPath: .spec.template.spec.rootVolume.sizeGiB + name: Disk GiB + type: integer + - jsonPath: .spec.template.spec.availabilityZone + name: Zone + type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + - jsonPath: .spec.template.spec.network.id + name: Network ID + priority: 1 + type: string + name: v1alpha1 schema: openAPIV3Schema: description: StackitMachineTemplate is the Schema for the stackitmachinetemplates @@ -168,3 +188,4 @@ spec: type: object served: true storage: true + subresources: {} diff --git a/controller/stackitmachine_controller_test.go b/controller/stackitmachine_controller_test.go index 968f5f9..56b6756 100644 --- a/controller/stackitmachine_controller_test.go +++ b/controller/stackitmachine_controller_test.go @@ -132,6 +132,7 @@ var _ = Describe("StackitMachine Controller", func() { Expect(got.Status.Ready).To(BeTrue()) Expect(got.Status.InstanceID).NotTo(BeEmpty()) Expect(got.Status.InstanceState).To(Equal("ACTIVE")) + Expect(got.Status.AvailabilityZone).To(Equal("eu01-1")) Expect(got.Status.ProviderID).To(Equal("stackit://" + got.Status.InstanceID)) Expect(got.Spec.ProviderID).NotTo(BeNil()) Expect(*got.Spec.ProviderID).To(Equal(got.Status.ProviderID)) diff --git a/scope/machine_scope.go b/scope/machine_scope.go index 23918cd..766c5e4 100644 --- a/scope/machine_scope.go +++ b/scope/machine_scope.go @@ -97,6 +97,7 @@ func (s *MachineScope) SetInstance(server *cloud.Server) string { providerID := cloud.NewProviderID(s.StackitCluster.Spec.ProjectID, s.StackitCluster.Spec.Region, server.ID) s.StackitMachine.Status.InstanceID = server.ID s.StackitMachine.Status.InstanceState = server.State + s.StackitMachine.Status.AvailabilityZone = server.AvailabilityZone s.StackitMachine.Spec.ProviderID = &providerID s.StackitMachine.Status.ProviderID = providerID s.StackitMachine.Status.Initialization.Provisioned = true @@ -106,4 +107,5 @@ func (s *MachineScope) SetInstance(server *cloud.Server) string { func (s *MachineScope) ClearInstance() { s.StackitMachine.Status.InstanceID = "" s.StackitMachine.Status.InstanceState = "" + s.StackitMachine.Status.AvailabilityZone = "" }