github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cci/v1/namespaces/requests.go (about) 1 package namespaces 2 3 import ( 4 "github.com/chnsz/golangsdk" 5 "github.com/chnsz/golangsdk/pagination" 6 ) 7 8 // CreateOpts allows to create a namespace using given parameters. 9 type CreateOpts struct { 10 // Kind is a string value representing the REST resource this object represents. 11 // Servers may infer this from the endpoint the client submits requests to. Cannot be updated. 12 // The value of this parameter is Namespace. 13 Kind string `json:"kind" required:"true"` 14 // ApiVersion defines the versioned schema of this representation of an object. 15 // Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. 16 // The value of this parameter is v1. 17 ApiVersion string `json:"apiVersion" required:"true"` 18 // Standard object metadata. 19 Metadata Metadata `json:"metadata" required:"true"` 20 // Spec defines the behavior of the Namespace. 21 Spec *Spec `json:"spec,omitempty"` 22 // Status describes the current status of a Namespace. 23 Status *Status `json:"status,omitempty"` 24 } 25 26 // Metadata is an object which will be build up standard object metadata. 27 type Metadata struct { 28 // Namespace name. Is required when creating resources, although some resources may allow a client to request the 29 // generation of an appropriate name automatically. 30 // Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. 31 // The name is consists of 1 to 63 characters and must be a regular expression [a-z0-9]([-a-z0-9]*[a-z0-9])?. 32 Name string `json:"name" required:"true"` 33 // An unstructured key value map stored with a resource that may be set by external tools to store and retrieve 34 // arbitrary metadata. They are not queryable and should be preserved when modifying objects. 35 Annotations Annotations `json:"annotations" required:"true"` 36 // An optional prefix used by the server to generate a unique name ONLY IF the Name field has not been provided. 37 // The name is consists of 1 to 253 characters and must bee a regular expression [a-z0-9]([-a-z0-9]*[a-z0-9])?. 38 GenerateName string `json:"generateName,omitempty"` 39 // An initializer is a controller which enforces some system invariant at object creation time. 40 Initializers *Initializers `json:"initializers,omitempty"` 41 // Map of string keys and values that can be used to organize and categorize (scope and select) objects. 42 // May match selectors of replication controllers and services. 43 Labels *Labels `json:"labels,omitempty"` 44 // List of objects depended by this object. 45 OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"` 46 // Finalizers is an opaque list of values that must be empty to permanently remove object from storage. 47 Finalizers []string `json:"finalizers,omitempty"` 48 // Enabled identify whether the resource is available. 49 Enabled bool `json:"enable,omitempty"` 50 } 51 52 // Annotations is an object which will be build up an unstructured key value map. 53 type Annotations struct { 54 // Flavor of the cluster to which the namespace belongs. 55 // Currently, GPU-accelerated and general-computing clusters are supported. 56 Flavor string `json:"namespace.kubernetes.io/flavor" required:"true"` 57 // Whether to enable elastic scheduling. 58 AutoExpend bool `json:"namespace.kubernetes.io/allowed-on-shared-node,string"` 59 // Whether to enable container network. 60 NetworkEnable string `json:"network.cci.io/ready-before-pod-run,omitempty"` 61 // IP Pool Warm-up for Namespace. 62 PoolSize int `json:"network.cci.io/warm-pool-size,omitempty,string"` 63 // IP Address Recycling Interval, in hour. 64 RecyclingInterval int `json:"network.cci.io/warm-pool-recycle-interval,omitempty,string"` 65 } 66 67 // Initializers is a controller which enforces some system invariant at namespace creation time. 68 type Initializers struct { 69 // List of initializers that must execute in order before this object is visible. 70 Pendings []Pending `json:"pending,omitempty"` 71 } 72 73 // Pending is an object of initializers that must execute in order before this object is visible. 74 type Pending struct { 75 // Name of the process that is responsible for initializing this object. 76 Name string `json:"name,omitempty"` 77 } 78 79 // Labels is an object that can be used to organize and categorize (scope and select) objects. 80 type Labels struct { 81 // Role-based access control (RBAC). 82 // If enabled, access to resources in the namespace will be controlled by RBAC policies. 83 RbacEnable bool `json:"rbac.authorization.cci.io/enable-k8s-rbac,string"` 84 // ID of enterprise project. 85 EnterpriseProjectID string `json:"sys_enterprise_project_id,omitempty"` 86 } 87 88 // OwnerReference is a list of objects depended by this object. 89 type OwnerReference struct { 90 // API version of the referent. 91 ApiVersion string `json:"apiVersion" required:"true"` 92 // Kind of the referent. 93 Kind string `json:"kind" required:"true"` 94 // Name of the referent. 95 Name string `json:"name" required:"true"` 96 // If true, AND if the owner has the "foregroundDeletion" finalizer, then the owner cannot be deleted from the 97 // key-value store until this reference is removed. Defaults to false. 98 BlockOwnerDeletion bool `json:"blockOwnerDeletion,omitempty"` 99 } 100 101 // Spec defines the behavior of the Namespace. 102 type Spec struct { 103 // Finalizers is an opaque list of values that must be empty to permanently remove object from storage. 104 Finalizers []string `json:"finalizers,omitempty"` 105 } 106 107 // Status describes the current status of a Namespace. 108 type Status struct { 109 Phase string `json:"phase,omitempty"` 110 } 111 112 // CreateOptsBuilder allows extensions to add additional parameters to the Create request. 113 type CreateOptsBuilder interface { 114 ToNamespaceCreateMap() (map[string]interface{}, error) 115 } 116 117 // ToNamespaceCreateMap builds a create request body from CreateOpts. 118 func (opts CreateOpts) ToNamespaceCreateMap() (map[string]interface{}, error) { 119 return golangsdk.BuildRequestBody(opts, "") 120 } 121 122 // Create accepts a CreateOpts struct and uses the values to create a new namespace. 123 func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { 124 b, err := opts.ToNamespaceCreateMap() 125 if err != nil { 126 r.Err = err 127 return 128 } 129 _, r.Err = client.Post(rootURL(client), b, &r.Body, nil) 130 return 131 } 132 133 // Get is a method to obtain the specified CCI namespace by name. 134 func Get(client *golangsdk.ServiceClient, ns string) (r GetResult) { 135 _, r.Err = client.Get(resourceURL(client, ns), &r.Body, nil) 136 return 137 } 138 139 // ListOpts allows to filter list data using given parameters. 140 type ListOpts struct { 141 Pretty string `q:"pretty"` 142 Continue string `q:"continue"` 143 LabelSelector string `q:"labelSelector"` 144 FieldSelector string `q:"fieldSelector"` 145 Limit string `q:"limit"` 146 IncludeUninitialized string `q:"includeUninitialized"` 147 Watch string `q:"watch"` 148 ResourceVersion string `q:"resourceVersion"` 149 Timeout string `q:"timeoutSeconds"` 150 } 151 152 // ToNamespaceListQuery is a method which to build a request query by the ListOpts. 153 func (opts ListOpts) ToNamespaceListQuery() (string, error) { 154 q, err := golangsdk.BuildQueryString(opts) 155 if err != nil { 156 return "", err 157 } 158 return q.String(), err 159 } 160 161 // ListOptsBuilder is an interface which to support request query build of the namespace search. 162 type ListOptsBuilder interface { 163 ToNamespaceListQuery() (string, error) 164 } 165 166 // List is a method to obtain the specified namespaces according to the ListOpts. 167 func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 168 url := rootURL(client) 169 if opts != nil { 170 query, err := opts.ToNamespaceListQuery() 171 if err != nil { 172 return pagination.Pager{Err: err} 173 } 174 url += query 175 } 176 177 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 178 return NamespacePage{pagination.SinglePageBase(r)} 179 }) 180 } 181 182 // Delete is a method to delete an existing namespace. 183 func Delete(client *golangsdk.ServiceClient, ns string) (r DeleteResult) { 184 _, r.Err = client.Delete(resourceURL(client, ns), nil) 185 return 186 }