sigs.k8s.io/cluster-api-provider-aws@v1.5.5/cmd/clusterawsadm/api/ami/v1beta1/types.go (about) 1 /* 2 Copyright 2021 The Kubernetes 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 v1beta1 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/runtime/schema" 22 ) 23 24 // Constants. 25 const ( 26 // AWSAMIKind defines an AMI kind. 27 AWSAMIKind = "AWSAMI" 28 29 // AWSAMIListKind defines an AWSAMIList kind. 30 AWSAMIListKind = "AWSAMIList" 31 ) 32 33 // AWSAMISpec defines an AMI. 34 type AWSAMISpec struct { 35 OS string `json:"os"` 36 Region string `json:"region"` 37 ImageID string `json:"imageID"` 38 KubernetesVersion string `json:"kubernetesVersion"` 39 } 40 41 // +kubebuilder:object:root=true 42 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 43 44 // AWSAMI defines an AMI. 45 type AWSAMI struct { 46 metav1.TypeMeta `json:",inline"` 47 metav1.ObjectMeta `json:"metadata,omitempty"` 48 Spec AWSAMISpec `json:"spec,omitempty"` 49 } 50 51 // +kubebuilder:object:root=true 52 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 53 54 // AWSAMIList defines a list of AMIs. 55 type AWSAMIList struct { 56 metav1.TypeMeta `json:",inline"` 57 metav1.ListMeta `json:"metadata,omitempty"` 58 Items []AWSAMI `json:"items"` 59 } 60 61 // ToTable will convert an AWSAMIList to a Table. 62 func (a *AWSAMIList) ToTable() *metav1.Table { 63 table := &metav1.Table{ 64 TypeMeta: metav1.TypeMeta{ 65 APIVersion: metav1.SchemeGroupVersion.String(), 66 Kind: "Table", 67 }, 68 ColumnDefinitions: []metav1.TableColumnDefinition{ 69 { 70 Name: "Kubernetes Version", 71 Type: "string", 72 }, 73 { 74 Name: "Region", 75 Type: "string", 76 }, 77 { 78 Name: "OS", 79 Type: "string", 80 }, 81 { 82 Name: "Name", 83 Type: "string", 84 }, 85 { 86 Name: "AMI ID", 87 Type: "string", 88 }, 89 }, 90 } 91 92 for _, ami := range a.Items { 93 row := metav1.TableRow{ 94 Cells: []interface{}{ami.Spec.KubernetesVersion, ami.Spec.Region, ami.Spec.OS, ami.GetName(), ami.Spec.ImageID}, 95 } 96 table.Rows = append(table.Rows, row) 97 } 98 return table 99 } 100 101 // GetObjectKind will return the ObjectKind of an AWSAMI. 102 func (a *AWSAMI) GetObjectKind() schema.ObjectKind { 103 return &metav1.TypeMeta{ 104 APIVersion: SchemeGroupVersion.String(), 105 Kind: AWSAMIKind, 106 } 107 } 108 109 // GetObjectKind will return the ObjectKind of an AWSAMIList. 110 func (a *AWSAMIList) GetObjectKind() schema.ObjectKind { 111 return &metav1.TypeMeta{ 112 APIVersion: SchemeGroupVersion.String(), 113 Kind: AWSAMIListKind, 114 } 115 }