github.com/giantswarm/apiextensions/v2@v2.6.2/pkg/apis/infrastructure/v1alpha2/networkpool.go (about) 1 package v1alpha2 2 3 import ( 4 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 5 6 "github.com/giantswarm/apiextensions/v2/pkg/annotation" 7 "github.com/giantswarm/apiextensions/v2/pkg/id" 8 "github.com/giantswarm/apiextensions/v2/pkg/label" 9 ) 10 11 // +k8s:deepcopy-gen=false 12 13 type NetworkPoolCRsConfig struct { 14 CIDRBlock string 15 NetworkPoolID string 16 Namespace string 17 Owner string 18 } 19 20 // +k8s:deepcopy-gen=false 21 22 type NetworkPoolCRs struct { 23 NetworkPool *NetworkPool 24 } 25 26 func NewNetworkPoolCRs(config NetworkPoolCRsConfig) (NetworkPoolCRs, error) { 27 // Default some essentials in case certain information are not given. E.g. 28 // the Tenant NetworkPoolID may be provided by the user. 29 { 30 if config.NetworkPoolID == "" { 31 config.NetworkPoolID = id.Generate() 32 } 33 if config.Namespace == "" { 34 config.Namespace = metav1.NamespaceDefault 35 } 36 } 37 38 networkPoolCR := newNetworkPoolCR(config) 39 40 crs := NetworkPoolCRs{ 41 NetworkPool: networkPoolCR, 42 } 43 44 return crs, nil 45 } 46 47 func newNetworkPoolCR(c NetworkPoolCRsConfig) *NetworkPool { 48 return &NetworkPool{ 49 TypeMeta: metav1.TypeMeta{ 50 Kind: kindNetworkPool, 51 APIVersion: SchemeGroupVersion.String(), 52 }, 53 ObjectMeta: metav1.ObjectMeta{ 54 Name: c.NetworkPoolID, 55 Namespace: c.Namespace, 56 Annotations: map[string]string{ 57 annotation.Docs: "https://docs.giantswarm.io/reference/cp-k8s-api/networkpools.infrastructure.giantswarm.io/", 58 }, 59 Labels: map[string]string{ 60 label.Organization: c.Owner, 61 }, 62 }, 63 Spec: NetworkPoolSpec{ 64 CIDRBlock: c.CIDRBlock, 65 }, 66 } 67 }