github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cce/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,omitempty"` 33 // An initializer is a controller which enforces some system invariant at object creation time. 34 Initializers *Initializers `json:"initializers,omitempty"` 35 // Enabled identify whether the resource is available. 36 Enabled bool `json:"enable,omitempty"` 37 // An optional prefix used by the server to generate a unique name ONLY IF the Name field has not been provided. 38 // The name is consists of 1 to 253 characters and must bee a regular expression [a-z0-9]([-a-z0-9]*[a-z0-9])?. 39 GenerateName string `json:"generateName,omitempty"` 40 // Map of string keys and values that can be used to organize and categorize (scope and select) objects. 41 // May match selectors of replication controllers and services. 42 Labels map[string]interface{} `json:"labels,omitempty"` 43 // An unstructured key value map stored with a resource that may be set by external tools to store and retrieve 44 // arbitrary metadata. They are not queryable and should be preserved when modifying objects. 45 Annotations map[string]interface{} `json:"annotations,omitempty"` 46 // List of objects depended by this object. 47 OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"` 48 // Finalizers is an opaque list of values that must be empty to permanently remove object from storage. 49 Finalizers []string `json:"finalizers,omitempty"` 50 } 51 52 // Initializers is a controller which enforces some system invariant at namespace creation time. 53 type Initializers struct { 54 // List of initializers that must execute in order before this object is visible. 55 Pendings []Pending `json:"pending,omitempty"` 56 } 57 58 // Pending is an object of initializers that must execute in order before this object is visible. 59 type Pending struct { 60 // Name of the process that is responsible for initializing this object. 61 Name string `json:"name,omitempty"` 62 } 63 64 // OwnerReference is a list of objects depended by this object. 65 type OwnerReference struct { 66 // API version of the referent. 67 ApiVersion string `json:"apiVersion" required:"true"` 68 // Kind of the referent. 69 Kind string `json:"kind" required:"true"` 70 // Name of the referent. 71 Name string `json:"name" required:"true"` 72 // If true, AND if the owner has the "foregroundDeletion" finalizer, then the owner cannot be deleted from the 73 // key-value store until this reference is removed. Defaults to false. 74 BlockOwnerDeletion bool `json:"blockOwnerDeletion,omitempty"` 75 } 76 77 // Spec defines the behavior of the Namespace. 78 type Spec struct { 79 // Finalizers is an opaque list of values that must be empty to permanently remove object from storage. 80 Finalizers []string `json:"finalizers,omitempty"` 81 } 82 83 // Status describes the current status of a Namespace. 84 type Status struct { 85 Phase string `json:"phase,omitempty"` 86 } 87 88 // CreateOptsBuilder allows extensions to add additional parameters to the Create request. 89 type CreateOptsBuilder interface { 90 ToNamespaceCreateMap() (map[string]interface{}, error) 91 } 92 93 // ToNamespaceCreateMap builds a create request body from CreateOpts. 94 func (opts CreateOpts) ToNamespaceCreateMap() (map[string]interface{}, error) { 95 return golangsdk.BuildRequestBody(opts, "") 96 } 97 98 // Create accepts a CreateOpts struct and uses the values to create a new namespace. 99 func Create(client *golangsdk.ServiceClient, clusterID string, opts CreateOptsBuilder) (r CreateResult) { 100 b, err := opts.ToNamespaceCreateMap() 101 if err != nil { 102 r.Err = err 103 return 104 } 105 _, r.Err = client.Post(rootURL(client, clusterID), b, &r.Body, nil) 106 return 107 } 108 109 // Get is a method to obtain the specified CCI namespace by name. 110 func Get(client *golangsdk.ServiceClient, clusterID, name string) (r GetResult) { 111 _, r.Err = client.Get(resourceURL(client, clusterID, name), &r.Body, nil) 112 return 113 } 114 115 // ListOpts allows to filter list data using given parameters. 116 type ListOpts struct { 117 Pretty string `q:"pretty"` 118 Continue string `q:"continue"` 119 LabelSelector string `q:"labelSelector"` 120 FieldSelector string `q:"fieldSelector"` 121 Limit string `q:"limit"` 122 IncludeUninitialized string `q:"includeUninitialized"` 123 Watch string `q:"watch"` 124 ResourceVersion string `q:"resourceVersion"` 125 Timeout string `q:"timeoutSeconds"` 126 } 127 128 // ToNamespaceListQuery is a method which to build a request query by the ListOpts. 129 func (opts ListOpts) ToNamespaceListQuery() (string, error) { 130 q, err := golangsdk.BuildQueryString(opts) 131 if err != nil { 132 return "", err 133 } 134 return q.String(), err 135 } 136 137 // ListOptsBuilder is an interface which to support request query build of the namespace search. 138 type ListOptsBuilder interface { 139 ToNamespaceListQuery() (string, error) 140 } 141 142 // List is a method to obtain the specified namespaces according to the ListOpts. 143 func List(client *golangsdk.ServiceClient, clusterID string, opts ListOptsBuilder) pagination.Pager { 144 url := rootURL(client, clusterID) 145 if opts != nil { 146 query, err := opts.ToNamespaceListQuery() 147 if err != nil { 148 return pagination.Pager{Err: err} 149 } 150 url += query 151 } 152 153 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { 154 return NamespacePage{pagination.SinglePageBase(r)} 155 }) 156 } 157 158 // Delete is a method to delete an existing namespace. 159 func Delete(client *golangsdk.ServiceClient, clusterID, name string) (r DeleteResult) { 160 reqOpt := &golangsdk.RequestOpts{ 161 JSONBody: map[string]string{ 162 "kind": "DeleteOptions", 163 "apiVersion": "v1", 164 }, 165 } 166 _, r.Err = client.Delete(resourceURL(client, clusterID, name), reqOpt) 167 return 168 }