From f3cc4f78653542b2a341b6bd2ffad61d19b48f69 Mon Sep 17 00:00:00 2001 From: Simon Murray Date: Wed, 7 Aug 2024 09:44:51 +0100 Subject: [PATCH] Rejig Neutron VLAN Provisioning So it transpires we were trying to piggy back on the stellar work by SCS for identity and allow a domain admin for provider networks, but alas Neutron has zero visibility of domains, and secondly only "admin" and "advsvc" can provision in a different project (hard coded, not a policy). Out one remaining option is to create a context that is for the "manager" user, but scoped to the user's project, and that can allow the provider network to be provisioned. --- Makefile | 3 +- charts/region/Chart.yaml | 2 +- ...n-cloud.org_openstackphysicalnetworks.yaml | 62 +++ ...on.unikorn-cloud.org_physicalnetworks.yaml | 68 +++- ...ion.unikorn-cloud.org_vlanallocations.yaml | 75 ++++ charts/region/templates/_helpers.tpl | 4 + .../identity-controller/clusterrole.yaml | 9 + .../clusterrole.yaml | 64 +++ .../clusterrolebinding.yaml | 14 + .../deployment.yaml | 40 ++ .../physical-network-controller/role.yaml | 23 ++ .../rolebinding.yaml | 14 + .../serviceaccount.yaml | 10 + .../region-controller/clusterrole.yaml | 2 + .../templates/region-controller/ingress.yaml | 6 +- charts/region/values.yaml | 4 + .../main.go | 27 ++ .../.dockerignore | 2 + .../Dockerfile | 8 + pkg/apis/unikorn/v1alpha1/helpers.go | 24 ++ pkg/apis/unikorn/v1alpha1/register.go | 3 +- pkg/apis/unikorn/v1alpha1/types.go | 77 +++- .../unikorn/v1alpha1/zz_generated.deepcopy.go | 223 ++++++++++- pkg/constants/constants.go | 3 + pkg/handler/handler.go | 75 +++- pkg/handler/region/region.go | 6 +- pkg/managers/physicalnetwork/manager.go | 79 ++++ pkg/openapi/client.go | 374 ++++++++++++++++-- pkg/openapi/router.go | 148 ++++++- pkg/openapi/schema.go | 182 ++++----- pkg/openapi/server.spec.yaml | 51 ++- pkg/openapi/types.go | 7 +- pkg/providers/allocation/vlan/vlan.go | 174 ++++++++ pkg/providers/interfaces.go | 7 +- pkg/providers/openstack/network.go | 63 ++- pkg/providers/openstack/network_test.go | 71 ---- pkg/providers/openstack/provider.go | 294 ++++++++++---- .../managers/identity/provisioner.go | 43 ++ .../managers/physicalnetwork/provisioner.go | 140 +++++++ 39 files changed, 2109 insertions(+), 372 deletions(-) create mode 100644 charts/region/crds/region.unikorn-cloud.org_openstackphysicalnetworks.yaml create mode 100644 charts/region/crds/region.unikorn-cloud.org_vlanallocations.yaml create mode 100644 charts/region/templates/physical-network-controller/clusterrole.yaml create mode 100644 charts/region/templates/physical-network-controller/clusterrolebinding.yaml create mode 100644 charts/region/templates/physical-network-controller/deployment.yaml create mode 100644 charts/region/templates/physical-network-controller/role.yaml create mode 100644 charts/region/templates/physical-network-controller/rolebinding.yaml create mode 100644 charts/region/templates/physical-network-controller/serviceaccount.yaml create mode 100644 cmd/unikorn-physical-network-controller/main.go create mode 100644 docker/unikorn-physical-network-controller/.dockerignore create mode 100644 docker/unikorn-physical-network-controller/Dockerfile create mode 100644 pkg/managers/physicalnetwork/manager.go create mode 100644 pkg/providers/allocation/vlan/vlan.go delete mode 100644 pkg/providers/openstack/network_test.go create mode 100644 pkg/provisioners/managers/physicalnetwork/provisioner.go diff --git a/Makefile b/Makefile index 071c40e..caa0b49 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,8 @@ REVISION := $(shell git rev-parse HEAD) # want to be amd64. CONTROLLERS = \ unikorn-region-controller \ - unikorn-identity-controller + unikorn-identity-controller \ + unikorn-physical-network-controller # Release will do cross compliation of all images for the 'all' target. # Note we aren't fucking about with docker here because that opens up a diff --git a/charts/region/Chart.yaml b/charts/region/Chart.yaml index ae5053f..37a39b0 100644 --- a/charts/region/Chart.yaml +++ b/charts/region/Chart.yaml @@ -11,5 +11,5 @@ icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/d dependencies: - name: unikorn-common - version: v0.1.6 + version: v0.1.8 repository: https://unikorn-cloud.github.io/helm-common diff --git a/charts/region/crds/region.unikorn-cloud.org_openstackphysicalnetworks.yaml b/charts/region/crds/region.unikorn-cloud.org_openstackphysicalnetworks.yaml new file mode 100644 index 0000000..d54837e --- /dev/null +++ b/charts/region/crds/region.unikorn-cloud.org_openstackphysicalnetworks.yaml @@ -0,0 +1,62 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: openstackphysicalnetworks.region.unikorn-cloud.org +spec: + group: region.unikorn-cloud.org + names: + categories: + - unikorn + kind: OpenstackPhysicalNetwork + listKind: OpenstackPhysicalNetworkList + plural: openstackphysicalnetworks + singular: openstackphysicalnetwork + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: OpenstackPhysicalNetwork defines a physical network beloning + to an identity. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + id: + description: ID is the network ID. + type: string + vlanID: + description: VlanID is the ID if the VLAN for IPAM. + type: integer + type: object + status: + type: object + required: + - spec + type: object + served: true + storage: true + subresources: {} diff --git a/charts/region/crds/region.unikorn-cloud.org_physicalnetworks.yaml b/charts/region/crds/region.unikorn-cloud.org_physicalnetworks.yaml index 4cc5f7f..43c9eca 100644 --- a/charts/region/crds/region.unikorn-cloud.org_physicalnetworks.yaml +++ b/charts/region/crds/region.unikorn-cloud.org_physicalnetworks.yaml @@ -47,21 +47,9 @@ spec: type: object spec: properties: - providerNetwork: - description: |- - ProviderNetwork is the provider network for port allocation of - virtual machines. - properties: - id: - description: ID is the network ID. - type: string - vlanID: - description: VlanID is the ID if the VLAN for IPAM. - type: integer - required: - - id - - vlanID - type: object + pause: + description: Pause, if true, will inhibit reconciliation. + type: boolean tags: description: |- Tags are an abitrary list of key/value pairs that a client @@ -82,10 +70,58 @@ spec: type: array type: object status: + properties: + conditions: + description: Current service state of a cluster manager. + items: + description: |- + Condition is a generic condition type for use across all resource types. + It's generic so that the underlying controller-manager functionality can + be shared across all resources. + properties: + lastTransitionTime: + description: Last time the condition transitioned from one status + to another. + format: date-time + type: string + message: + description: Human-readable message indicating details about + last transition. + type: string + reason: + description: Unique, one-word, CamelCase reason for the condition's + last transition. + enum: + - Provisioning + - Provisioned + - Cancelled + - Errored + - Deprovisioning + - Deprovisioned + type: string + status: + description: |- + Status is the status of the condition. + Can be True, False, Unknown. + type: string + type: + description: Type is the type of the condition. + enum: + - Available + type: string + required: + - lastTransitionTime + - message + - reason + - status + - type + type: object + type: array type: object required: - spec type: object served: true storage: true - subresources: {} + subresources: + status: {} diff --git a/charts/region/crds/region.unikorn-cloud.org_vlanallocations.yaml b/charts/region/crds/region.unikorn-cloud.org_vlanallocations.yaml new file mode 100644 index 0000000..88b29b8 --- /dev/null +++ b/charts/region/crds/region.unikorn-cloud.org_vlanallocations.yaml @@ -0,0 +1,75 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: vlanallocations.region.unikorn-cloud.org +spec: + group: region.unikorn-cloud.org + names: + categories: + - unikorn + kind: VLANAllocation + listKind: VLANAllocationList + plural: vlanallocations + singular: vlanallocation + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: |- + VLANAllocation is used to manage VLAN allocations. Only a single instance is + allowed per region. As this is a custom resource, we are guaranteed atomicity + due to Kubernetes' speculative locking implementation. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + allocations: + description: Allocations are an explcit set of VLAN allocations. + items: + properties: + id: + description: ID is the VLAN ID. + type: integer + physicalNetworkID: + description: |- + PhysicalNetworkID is the physical network/provider specific physical network + identifier that owns this entry. + type: string + required: + - id + - physicalNetworkID + type: object + type: array + type: object + status: + type: object + required: + - spec + type: object + served: true + storage: true + subresources: {} diff --git a/charts/region/templates/_helpers.tpl b/charts/region/templates/_helpers.tpl index 18bf26d..3a9e961 100644 --- a/charts/region/templates/_helpers.tpl +++ b/charts/region/templates/_helpers.tpl @@ -9,6 +9,10 @@ Create the container images {{- .Values.identityController.image | default (printf "%s/unikorn-identity-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} {{- end }} +{{- define "unikorn.physicalNetworkControllerImage" -}} +{{- .Values.physicalNetworkController.image | default (printf "%s/unikorn-physical-network-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} +{{- end }} + {{/* Create image pull secrets */}} diff --git a/charts/region/templates/identity-controller/clusterrole.yaml b/charts/region/templates/identity-controller/clusterrole.yaml index ab41885..4beb737 100644 --- a/charts/region/templates/identity-controller/clusterrole.yaml +++ b/charts/region/templates/identity-controller/clusterrole.yaml @@ -31,6 +31,15 @@ rules: - create - update - delete +# Cascading deletion. +- apiGroups: + - region.unikorn-cloud.org + resources: + - physicalnetworks + verbs: + - list + - watch + - delete - apiGroups: - "" resources: diff --git a/charts/region/templates/physical-network-controller/clusterrole.yaml b/charts/region/templates/physical-network-controller/clusterrole.yaml new file mode 100644 index 0000000..fa0d49d --- /dev/null +++ b/charts/region/templates/physical-network-controller/clusterrole.yaml @@ -0,0 +1,64 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: unikorn-physical-network-controller + labels: + {{- include "unikorn.labels" . | nindent 4 }} +rules: +# Orchestrate Unikorn resources (my job). +- apiGroups: + - region.unikorn-cloud.org + resources: + - identities + - openstackidentities + verbs: + - list + - watch +- apiGroups: + - region.unikorn-cloud.org + resources: + - physicalnetworks + verbs: + - list + - watch + - update + - patch +- apiGroups: + - region.unikorn-cloud.org + resources: + - physicalnetworks/status + verbs: + - update +- apiGroups: + - region.unikorn-cloud.org + resources: + - openstackphysicalnetworks + verbs: + - list + - watch + - create + - update + - delete +- apiGroups: + - region.unikorn-cloud.org + resources: + - vlanallocations + verbs: + - list + - watch + - create + - update +- apiGroups: + - "" + resources: + - secrets + verbs: + - list + - watch +- apiGroups: + - region.unikorn-cloud.org + resources: + - regions + verbs: + - list + - watch diff --git a/charts/region/templates/physical-network-controller/clusterrolebinding.yaml b/charts/region/templates/physical-network-controller/clusterrolebinding.yaml new file mode 100644 index 0000000..0762b51 --- /dev/null +++ b/charts/region/templates/physical-network-controller/clusterrolebinding.yaml @@ -0,0 +1,14 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: unikorn-physical-network-controller + labels: + {{- include "unikorn.labels" . | nindent 4 }} +subjects: +- kind: ServiceAccount + namespace: {{ .Release.Namespace }} + name: unikorn-physical-network-controller +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: unikorn-physical-network-controller diff --git a/charts/region/templates/physical-network-controller/deployment.yaml b/charts/region/templates/physical-network-controller/deployment.yaml new file mode 100644 index 0000000..747e64a --- /dev/null +++ b/charts/region/templates/physical-network-controller/deployment.yaml @@ -0,0 +1,40 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: unikorn-physical-network-controller + labels: + {{- include "unikorn.labels" . | nindent 4 }} +spec: + replicas: 1 + selector: + matchLabels: + app: unikorn-physical-network-controller + template: + metadata: + labels: + app: unikorn-physical-network-controller + spec: + containers: + - name: unikorn-physical-network-controller + image: {{ include "unikorn.physicalNetworkControllerImage" . }} + args: + {{- include "unikorn.otlp.flags" . | nindent 8 }} + ports: + - name: http + containerPort: 6080 + - name: prometheus + containerPort: 8080 + - name: pprof + containerPort: 6060 + resources: + requests: + cpu: "50m" + memory: 50Mi + limits: + cpu: "100m" + memory: 100Mi + securityContext: + readOnlyRootFilesystem: true + serviceAccountName: unikorn-physical-network-controller + securityContext: + runAsNonRoot: true diff --git a/charts/region/templates/physical-network-controller/role.yaml b/charts/region/templates/physical-network-controller/role.yaml new file mode 100644 index 0000000..173cb53 --- /dev/null +++ b/charts/region/templates/physical-network-controller/role.yaml @@ -0,0 +1,23 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: unikorn-physical-network-controller + labels: + {{- include "unikorn.labels" . | nindent 4 }} +rules: +# Controller prerequisites. +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - create + - get + - update +- apiGroups: + - "" + resources: + - events + verbs: + - create + - update diff --git a/charts/region/templates/physical-network-controller/rolebinding.yaml b/charts/region/templates/physical-network-controller/rolebinding.yaml new file mode 100644 index 0000000..d23e978 --- /dev/null +++ b/charts/region/templates/physical-network-controller/rolebinding.yaml @@ -0,0 +1,14 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: unikorn-physical-network-controller + labels: + {{- include "unikorn.labels" . | nindent 4 }} +subjects: +- kind: ServiceAccount + namespace: {{ .Release.Namespace }} + name: unikorn-physical-network-controller +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: unikorn-physical-network-controller diff --git a/charts/region/templates/physical-network-controller/serviceaccount.yaml b/charts/region/templates/physical-network-controller/serviceaccount.yaml new file mode 100644 index 0000000..7f6d280 --- /dev/null +++ b/charts/region/templates/physical-network-controller/serviceaccount.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: unikorn-physical-network-controller + labels: + {{- include "unikorn.labels" . | nindent 4 }} +{{- with ( include "unikorn.imagePullSecrets" . ) }} +imagePullSecrets: +{{ . }} +{{- end }} diff --git a/charts/region/templates/region-controller/clusterrole.yaml b/charts/region/templates/region-controller/clusterrole.yaml index dbf86bc..7b22087 100644 --- a/charts/region/templates/region-controller/clusterrole.yaml +++ b/charts/region/templates/region-controller/clusterrole.yaml @@ -17,6 +17,7 @@ rules: - region.unikorn-cloud.org resources: - identities + - physicalnetworks verbs: - list - watch @@ -26,6 +27,7 @@ rules: - region.unikorn-cloud.org resources: - openstackidentities + - openstackphysicalnetworks verbs: - list - watch diff --git a/charts/region/templates/region-controller/ingress.yaml b/charts/region/templates/region-controller/ingress.yaml index 16418c6..336ef09 100644 --- a/charts/region/templates/region-controller/ingress.yaml +++ b/charts/region/templates/region-controller/ingress.yaml @@ -6,11 +6,7 @@ metadata: {{- include "unikorn.labels" . | nindent 4 }} annotations: {{- include "unikorn.ingress.clusterIssuer.annotations" . | nindent 4 }} - # mTLS is used to authenticate other Unikorn services - nginx.ingress.kubernetes.io/auth-tls-verify-client: optional - nginx.ingress.kubernetes.io/auth-tls-secret: cert-manager/unikorn-client-ca - nginx.ingress.kubernetes.io/auth-tls-verify-depth: "1" - nginx.ingress.kubernetes.io/auth-tls-pass-certificate-to-upstream: "true" + {{- include "unikorn.ingress.mtls.annotations" . | nindent 4 }} {{- if (include "unikorn.ingress.externalDNS" .) }} external-dns.alpha.kubernetes.io/hostname: {{ include "unikorn.region.host" . }} {{- end }} diff --git a/charts/region/values.yaml b/charts/region/values.yaml index 64c49d5..f31a74c 100644 --- a/charts/region/values.yaml +++ b/charts/region/values.yaml @@ -106,6 +106,10 @@ identityController: # Allow override of the identity controller image. image: +physicalNetworkController: + # Allow override of the identity controller image. + image: + # Sets the DNS hosts/X.509 Certs. region: host: region.unikorn-cloud.org diff --git a/cmd/unikorn-physical-network-controller/main.go b/cmd/unikorn-physical-network-controller/main.go new file mode 100644 index 0000000..d7a4959 --- /dev/null +++ b/cmd/unikorn-physical-network-controller/main.go @@ -0,0 +1,27 @@ +/* +Copyright 2022-2024 EscherCloud. +Copyright 2024 the Unikorn Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "github.com/unikorn-cloud/core/pkg/manager" + "github.com/unikorn-cloud/region/pkg/managers/physicalnetwork" +) + +func main() { + manager.Run(&physicalnetwork.Factory{}) +} diff --git a/docker/unikorn-physical-network-controller/.dockerignore b/docker/unikorn-physical-network-controller/.dockerignore new file mode 100644 index 0000000..e2d7070 --- /dev/null +++ b/docker/unikorn-physical-network-controller/.dockerignore @@ -0,0 +1,2 @@ +* +!bin/*-linux-gnu/unikorn-physical-network-controller diff --git a/docker/unikorn-physical-network-controller/Dockerfile b/docker/unikorn-physical-network-controller/Dockerfile new file mode 100644 index 0000000..92e3025 --- /dev/null +++ b/docker/unikorn-physical-network-controller/Dockerfile @@ -0,0 +1,8 @@ +FROM gcr.io/distroless/static:nonroot + +# This is implcitly created by 'docker buildx build' +ARG TARGETARCH + +COPY bin/${TARGETARCH}-linux-gnu/unikorn-physical-network-controller / + +ENTRYPOINT ["/unikorn-physical-network-controller"] diff --git a/pkg/apis/unikorn/v1alpha1/helpers.go b/pkg/apis/unikorn/v1alpha1/helpers.go index 041e222..f0b528b 100644 --- a/pkg/apis/unikorn/v1alpha1/helpers.go +++ b/pkg/apis/unikorn/v1alpha1/helpers.go @@ -46,3 +46,27 @@ func (c *Identity) StatusConditionWrite(t unikornv1core.ConditionType, status co func (c *Identity) ResourceLabels() (labels.Set, error) { return nil, nil } + +// Paused implements the ReconcilePauser interface. +func (c *PhysicalNetwork) Paused() bool { + return c.Spec.Pause +} + +// StatusConditionRead scans the status conditions for an existing condition whose type +// matches. +func (c *PhysicalNetwork) StatusConditionRead(t unikornv1core.ConditionType) (*unikornv1core.Condition, error) { + return unikornv1core.GetCondition(c.Status.Conditions, t) +} + +// StatusConditionWrite either adds or updates a condition in the cluster manager status. +// If the condition, status and message match an existing condition the update is +// ignored. +func (c *PhysicalNetwork) StatusConditionWrite(t unikornv1core.ConditionType, status corev1.ConditionStatus, reason unikornv1core.ConditionReason, message string) { + unikornv1core.UpdateCondition(&c.Status.Conditions, t, status, reason, message) +} + +// ResourceLabels generates a set of labels to uniquely identify the resource +// if it were to be placed in a single global namespace. +func (c *PhysicalNetwork) ResourceLabels() (labels.Set, error) { + return nil, nil +} diff --git a/pkg/apis/unikorn/v1alpha1/register.go b/pkg/apis/unikorn/v1alpha1/register.go index fde2a74..8c54411 100644 --- a/pkg/apis/unikorn/v1alpha1/register.go +++ b/pkg/apis/unikorn/v1alpha1/register.go @@ -50,8 +50,9 @@ var ( func init() { SchemeBuilder.Register(&Region{}, &RegionList{}) SchemeBuilder.Register(&Identity{}, &IdentityList{}) - SchemeBuilder.Register(&OpenstackIdentity{}, &OpenstackIdentityList{}) SchemeBuilder.Register(&PhysicalNetwork{}, &PhysicalNetworkList{}) + SchemeBuilder.Register(&OpenstackIdentity{}, &OpenstackIdentityList{}) + SchemeBuilder.Register(&OpenstackPhysicalNetwork{}, &OpenstackPhysicalNetworkList{}) } // Resource maps a resource type to a group resource. diff --git a/pkg/apis/unikorn/v1alpha1/types.go b/pkg/apis/unikorn/v1alpha1/types.go index 29d82d9..933ee0d 100644 --- a/pkg/apis/unikorn/v1alpha1/types.go +++ b/pkg/apis/unikorn/v1alpha1/types.go @@ -360,6 +360,7 @@ type PhysicalNetworkList struct { // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +kubebuilder:resource:scope=Namespaced,categories=unikorn +// +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="status",type="string",JSONPath=".status.conditions[?(@.type==\"Available\")].reason" // +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" type PhysicalNetwork struct { @@ -370,20 +371,82 @@ type PhysicalNetwork struct { } type PhysicalNetworkSpec struct { + // Pause, if true, will inhibit reconciliation. + Pause bool `json:"pause,omitempty"` // Tags are an abitrary list of key/value pairs that a client // may populate to store metadata for the resource. Tags TagList `json:"tags,omitempty"` - // ProviderNetwork is the provider network for port allocation of - // virtual machines. - ProviderNetwork *OpenstackProviderNetworkSpec `json:"providerNetwork,omitempty"` } -type OpenstackProviderNetworkSpec struct { +type PhysicalNetworkStatus struct { + // Current service state of a cluster manager. + Conditions []unikornv1core.Condition `json:"conditions,omitempty"` +} + +// OpenstackPhysicalNetworkList s a typed list of physical networks. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type OpenstackPhysicalNetworkList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []OpenstackPhysicalNetwork `json:"items"` +} + +// OpenstackPhysicalNetwork defines a physical network beloning to an identity. +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:resource:scope=Namespaced,categories=unikorn +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +type OpenstackPhysicalNetwork struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec OpenstackPhysicalNetworkSpec `json:"spec"` + Status OpenstackPhysicalNetworkStatus `json:"status,omitempty"` +} + +type OpenstackPhysicalNetworkSpec struct { // ID is the network ID. - ID string `json:"id"` + ID *string `json:"id,omitempty"` // VlanID is the ID if the VLAN for IPAM. - VlanID int `json:"vlanID"` + VlanID *int `json:"vlanID,omitempty"` } -type PhysicalNetworkStatus struct { +type OpenstackPhysicalNetworkStatus struct { +} + +// VLANAllocationList is a typed list of VLAN allocations. +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +type VLANAllocationList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []VLANAllocation `json:"items"` +} + +// VLANAllocation is used to manage VLAN allocations. Only a single instance is +// allowed per region. As this is a custom resource, we are guaranteed atomicity +// due to Kubernetes' speculative locking implementation. +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object +// +kubebuilder:resource:scope=Namespaced,categories=unikorn +// +kubebuilder:printcolumn:name="age",type="date",JSONPath=".metadata.creationTimestamp" +type VLANAllocation struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + Spec VLANAllocationSpec `json:"spec"` + Status VLANAllocationStatus `json:"status,omitempty"` +} + +type VLANAllocationSpec struct { + // Allocations are an explcit set of VLAN allocations. + Allocations []VLANAllocationEntry `json:"allocations,omitempty"` +} + +type VLANAllocationEntry struct { + // ID is the VLAN ID. + ID int `json:"id"` + // PhysicalNetworkID is the physical network/provider specific physical network + // identifier that owns this entry. + PhysicalNetworkID string `json:"physicalNetworkID"` +} + +type VLANAllocationStatus struct { } diff --git a/pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go index 4e23872..200b310 100644 --- a/pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go @@ -481,17 +481,104 @@ func (in *OpenstackIdentityStatus) DeepCopy() *OpenstackIdentityStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *OpenstackProviderNetworkSpec) DeepCopyInto(out *OpenstackProviderNetworkSpec) { +func (in *OpenstackPhysicalNetwork) DeepCopyInto(out *OpenstackPhysicalNetwork) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenstackPhysicalNetwork. +func (in *OpenstackPhysicalNetwork) DeepCopy() *OpenstackPhysicalNetwork { + if in == nil { + return nil + } + out := new(OpenstackPhysicalNetwork) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *OpenstackPhysicalNetwork) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenstackPhysicalNetworkList) DeepCopyInto(out *OpenstackPhysicalNetworkList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenstackPhysicalNetwork, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenstackPhysicalNetworkList. +func (in *OpenstackPhysicalNetworkList) DeepCopy() *OpenstackPhysicalNetworkList { + if in == nil { + return nil + } + out := new(OpenstackPhysicalNetworkList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *OpenstackPhysicalNetworkList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenstackPhysicalNetworkSpec) DeepCopyInto(out *OpenstackPhysicalNetworkSpec) { + *out = *in + if in.ID != nil { + in, out := &in.ID, &out.ID + *out = new(string) + **out = **in + } + if in.VlanID != nil { + in, out := &in.VlanID, &out.VlanID + *out = new(int) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenstackPhysicalNetworkSpec. +func (in *OpenstackPhysicalNetworkSpec) DeepCopy() *OpenstackPhysicalNetworkSpec { + if in == nil { + return nil + } + out := new(OpenstackPhysicalNetworkSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenstackPhysicalNetworkStatus) DeepCopyInto(out *OpenstackPhysicalNetworkStatus) { *out = *in return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenstackProviderNetworkSpec. -func (in *OpenstackProviderNetworkSpec) DeepCopy() *OpenstackProviderNetworkSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenstackPhysicalNetworkStatus. +func (in *OpenstackPhysicalNetworkStatus) DeepCopy() *OpenstackPhysicalNetworkStatus { if in == nil { return nil } - out := new(OpenstackProviderNetworkSpec) + out := new(OpenstackPhysicalNetworkStatus) in.DeepCopyInto(out) return out } @@ -502,7 +589,7 @@ func (in *PhysicalNetwork) DeepCopyInto(out *PhysicalNetwork) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) return } @@ -565,11 +652,6 @@ func (in *PhysicalNetworkSpec) DeepCopyInto(out *PhysicalNetworkSpec) { *out = make(TagList, len(*in)) copy(*out, *in) } - if in.ProviderNetwork != nil { - in, out := &in.ProviderNetwork, &out.ProviderNetwork - *out = new(OpenstackProviderNetworkSpec) - **out = **in - } return } @@ -586,6 +668,13 @@ func (in *PhysicalNetworkSpec) DeepCopy() *PhysicalNetworkSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PhysicalNetworkStatus) DeepCopyInto(out *PhysicalNetworkStatus) { *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]unikornv1alpha1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -901,6 +990,120 @@ func (in TagList) DeepCopy() TagList { return *out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VLANAllocation) DeepCopyInto(out *VLANAllocation) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + out.Status = in.Status + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VLANAllocation. +func (in *VLANAllocation) DeepCopy() *VLANAllocation { + if in == nil { + return nil + } + out := new(VLANAllocation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *VLANAllocation) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VLANAllocationEntry) DeepCopyInto(out *VLANAllocationEntry) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VLANAllocationEntry. +func (in *VLANAllocationEntry) DeepCopy() *VLANAllocationEntry { + if in == nil { + return nil + } + out := new(VLANAllocationEntry) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VLANAllocationList) DeepCopyInto(out *VLANAllocationList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]VLANAllocation, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VLANAllocationList. +func (in *VLANAllocationList) DeepCopy() *VLANAllocationList { + if in == nil { + return nil + } + out := new(VLANAllocationList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *VLANAllocationList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VLANAllocationSpec) DeepCopyInto(out *VLANAllocationSpec) { + *out = *in + if in.Allocations != nil { + in, out := &in.Allocations, &out.Allocations + *out = make([]VLANAllocationEntry, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VLANAllocationSpec. +func (in *VLANAllocationSpec) DeepCopy() *VLANAllocationSpec { + if in == nil { + return nil + } + out := new(VLANAllocationSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VLANAllocationStatus) DeepCopyInto(out *VLANAllocationStatus) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VLANAllocationStatus. +func (in *VLANAllocationStatus) DeepCopy() *VLANAllocationStatus { + if in == nil { + return nil + } + out := new(VLANAllocationStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VLANSegment) DeepCopyInto(out *VLANSegment) { *out = *in diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 66b9b9c..5101d74 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -51,4 +51,7 @@ const ( // IdentityLabel creates an indexable linkage between resources and an // owning identity. IdentityLabel = "regions.unikorn-cloud.org/identity-id" + // PhysicalNetworkLabel creates an indexable linkage between resources + // and an owning entity. + PhysicalNetworkLabel = "regions.unikorn-cloud.org/phyiscal-network-id" ) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 651bc42..3c04133 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -85,9 +85,9 @@ func (h *Handler) setUncacheable(w http.ResponseWriter) { } func (h *Handler) getIdentity(ctx context.Context, id string) (*unikornv1.Identity, error) { - identity := &unikornv1.Identity{} + resource := &unikornv1.Identity{} - if err := h.client.Get(ctx, client.ObjectKey{Namespace: h.namespace, Name: id}, identity); err != nil { + if err := h.client.Get(ctx, client.ObjectKey{Namespace: h.namespace, Name: id}, resource); err != nil { if kerrors.IsNotFound(err) { return nil, errors.HTTPNotFound().WithError(err) } @@ -95,7 +95,21 @@ func (h *Handler) getIdentity(ctx context.Context, id string) (*unikornv1.Identi return nil, errors.OAuth2ServerError("unable to lookup identity").WithError(err) } - return identity, nil + return resource, nil +} + +func (h *Handler) getPhysicalNetwork(ctx context.Context, id string) (*unikornv1.PhysicalNetwork, error) { + resource := &unikornv1.PhysicalNetwork{} + + if err := h.client.Get(ctx, client.ObjectKey{Namespace: h.namespace, Name: id}, resource); err != nil { + if kerrors.IsNotFound(err) { + return nil, errors.HTTPNotFound().WithError(err) + } + + return nil, errors.OAuth2ServerError("unable to physical network identity").WithError(err) + } + + return resource, nil } func (h *Handler) GetApiV1OrganizationsOrganizationIDRegions(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter) { @@ -499,7 +513,7 @@ func convertPhysicalNetwork(in *unikornv1.PhysicalNetwork) *openapi.PhysicalNetw return out } -func (h *Handler) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter, identityID openapi.IdentityIDParameter) { +func (h *Handler) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter, identityID openapi.IdentityIDParameter) { if err := rbac.AllowProjectScope(r.Context(), "identities", identityapi.Create, organizationID, projectID); err != nil { errors.HandleError(w, r, err) return @@ -518,19 +532,66 @@ func (h *Handler) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitie return } - provider, err := region.NewClient(h.client, h.namespace).Provider(r.Context(), identity.Labels[constants.RegionLabel]) + userinfo, err := authorization.UserinfoFromContext(r.Context()) if err != nil { + errors.HandleError(w, r, errors.OAuth2ServerError("unable to get userinfo").WithError(err)) + return + } + + network := &unikornv1.PhysicalNetwork{ + ObjectMeta: conversion.NewObjectMetadata(&request.Metadata, h.namespace, userinfo.Sub).WithOrganization(organizationID).WithProject(projectID).WithLabel(constants.RegionLabel, identity.Labels[constants.RegionLabel]).WithLabel(constants.IdentityLabel, identityID).Get(), + } + + if request.Spec != nil { + network.Spec.Tags = generateTagList(request.Spec.Tags) + } + + if err := h.client.Create(r.Context(), network); err != nil { + errors.HandleError(w, r, errors.OAuth2ServerError("unable to create physical network").WithError(err)) + return + } + + util.WriteJSONResponse(w, r, http.StatusCreated, convertPhysicalNetwork(network)) +} + +func (h *Handler) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter, identityID openapi.IdentityIDParameter, physicalNetworkID openapi.PhysicalNetworkIDParameter) { + if err := rbac.AllowProjectScope(r.Context(), "identities", identityapi.Read, organizationID, projectID); err != nil { errors.HandleError(w, r, err) return } - network, err := provider.CreatePhysicalNetwork(r.Context(), identity, request) + resource, err := h.getPhysicalNetwork(r.Context(), physicalNetworkID) if err != nil { errors.HandleError(w, r, err) return } - util.WriteJSONResponse(w, r, http.StatusCreated, convertPhysicalNetwork(network)) + util.WriteJSONResponse(w, r, http.StatusOK, convertPhysicalNetwork(resource)) +} + +func (h *Handler) DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request, organizationID openapi.OrganizationIDParameter, projectID openapi.ProjectIDParameter, identityID openapi.IdentityIDParameter, physicalNetworkID openapi.PhysicalNetworkIDParameter) { + if err := rbac.AllowProjectScope(r.Context(), "identities", identityapi.Delete, organizationID, projectID); err != nil { + errors.HandleError(w, r, err) + return + } + + resource, err := h.getPhysicalNetwork(r.Context(), physicalNetworkID) + if err != nil { + errors.HandleError(w, r, err) + return + } + + if err := h.client.Delete(r.Context(), resource); err != nil { + if kerrors.IsNotFound(err) { + errors.HandleError(w, r, errors.HTTPNotFound().WithError(err)) + return + } + + errors.HandleError(w, r, errors.OAuth2ServerError("unable to delete physical network").WithError(err)) + return + } + + w.WriteHeader(http.StatusAccepted) } func convertExternalNetwork(in providers.ExternalNetwork) openapi.ExternalNetwork { diff --git a/pkg/handler/region/region.go b/pkg/handler/region/region.go index 35a654e..6489c6c 100644 --- a/pkg/handler/region/region.go +++ b/pkg/handler/region/region.go @@ -76,11 +76,11 @@ func findRegion(regions *unikornv1.RegionList, regionID string) (*unikornv1.Regi //nolint:gochecknoglobals var cache = map[string]providers.Provider{} -func (c Client) newProvider(region *unikornv1.Region) (providers.Provider, error) { +func (c Client) newProvider(ctx context.Context, region *unikornv1.Region) (providers.Provider, error) { //nolint:gocritic switch region.Spec.Provider { case unikornv1.ProviderOpenstack: - return openstack.New(c.client, region), nil + return openstack.New(ctx, c.client, region) } return nil, ErrRegionProviderUnimplmented @@ -101,7 +101,7 @@ func (c *Client) Provider(ctx context.Context, regionID string) (providers.Provi return provider, nil } - provider, err := c.newProvider(region) + provider, err := c.newProvider(ctx, region) if err != nil { return nil, err } diff --git a/pkg/managers/physicalnetwork/manager.go b/pkg/managers/physicalnetwork/manager.go new file mode 100644 index 0000000..89a3b32 --- /dev/null +++ b/pkg/managers/physicalnetwork/manager.go @@ -0,0 +1,79 @@ +/* +Copyright 2024 the Unikorn Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package physicalnetwork + +import ( + coreclient "github.com/unikorn-cloud/core/pkg/client" + coremanager "github.com/unikorn-cloud/core/pkg/manager" + "github.com/unikorn-cloud/core/pkg/manager/options" + unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" + "github.com/unikorn-cloud/region/pkg/constants" + "github.com/unikorn-cloud/region/pkg/provisioners/managers/physicalnetwork" + + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" + "sigs.k8s.io/controller-runtime/pkg/handler" + "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/predicate" + "sigs.k8s.io/controller-runtime/pkg/reconcile" + "sigs.k8s.io/controller-runtime/pkg/source" +) + +// Factory provides methods that can build a type specific controller. +type Factory struct{} + +var _ coremanager.ControllerFactory = &Factory{} + +// Metadata returns the application, version and revision. +func (*Factory) Metadata() (string, string, string) { + return constants.Application, constants.Version, constants.Revision +} + +// Options returns any options to be added to the CLI flags and passed to the reconciler. +func (*Factory) Options() coremanager.ControllerOptions { + return nil +} + +// Reconciler returns a new reconciler instance. +func (*Factory) Reconciler(options *options.Options, controllerOptions coremanager.ControllerOptions, manager manager.Manager) reconcile.Reconciler { + return coremanager.NewReconciler(options, controllerOptions, manager, physicalnetwork.New) +} + +// RegisterWatches adds any watches that would trigger a reconcile. +func (*Factory) RegisterWatches(manager manager.Manager, controller controller.Controller) error { + // Any changes to the physicalnetwork spec, trigger a reconcile. + if err := controller.Watch(source.Kind(manager.GetCache(), &unikornv1.PhysicalNetwork{}, &handler.TypedEnqueueRequestForObject[*unikornv1.PhysicalNetwork]{}, &predicate.TypedGenerationChangedPredicate[*unikornv1.PhysicalNetwork]{})); err != nil { + return err + } + + return nil +} + +// Upgrade can perform metadata upgrades of all versioned resources on restart/upgrade +// of the controller. This must not affect the spec in any way as it causes split brain +// and potential fail. +func (*Factory) Upgrade(_ client.Client) error { + return nil +} + +// Schemes allows controllers to add types to the client beyond +// the defaults defined in this repository. +func (*Factory) Schemes() []coreclient.SchemeAdder { + return []coreclient.SchemeAdder{ + unikornv1.AddToScheme, + } +} diff --git a/pkg/openapi/client.go b/pkg/openapi/client.go index d0c6baa..50a83c3 100644 --- a/pkg/openapi/client.go +++ b/pkg/openapi/client.go @@ -104,10 +104,16 @@ type ClientInterface interface { // GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID request GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, reqEditors ...RequestEditorFn) (*http.Response, error) - // PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBody request with any body - PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBody(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + // PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBody request with any body + PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBody(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) - PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + + // DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID request + DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*http.Response, error) + + // GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID request + GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*http.Response, error) // GetApiV1OrganizationsOrganizationIDRegions request GetApiV1OrganizationsOrganizationIDRegions(ctx context.Context, organizationID OrganizationIDParameter, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -182,8 +188,20 @@ func (c *Client) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesI return c.Client.Do(req) } -func (c *Client) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBody(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequestWithBody(c.Server, organizationID, projectID, identityID, contentType, body) +func (c *Client) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBody(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequestWithBody(c.Server, organizationID, projectID, identityID, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequest(c.Server, organizationID, projectID, identityID, body) if err != nil { return nil, err } @@ -194,8 +212,20 @@ func (c *Client) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentities return c.Client.Do(req) } -func (c *Client) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { - req, err := NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequest(c.Server, organizationID, projectID, identityID, body) +func (c *Client) DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDRequest(c.Server, organizationID, projectID, identityID, physicalNetworkID) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDRequest(c.Server, organizationID, projectID, identityID, physicalNetworkID) if err != nil { return nil, err } @@ -438,19 +468,19 @@ func NewGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID return req, nil } -// NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequest calls the generic PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks builder with application/json body -func NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequest(server string, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody) (*http.Request, error) { +// NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequest calls the generic PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks builder with application/json body +func NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequest(server string, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody) (*http.Request, error) { var bodyReader io.Reader buf, err := json.Marshal(body) if err != nil { return nil, err } bodyReader = bytes.NewReader(buf) - return NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequestWithBody(server, organizationID, projectID, identityID, "application/json", bodyReader) + return NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequestWithBody(server, organizationID, projectID, identityID, "application/json", bodyReader) } -// NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequestWithBody generates requests for PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks with any type of body -func NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksRequestWithBody(server string, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader) (*http.Request, error) { +// NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequestWithBody generates requests for PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks with any type of body +func NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksRequestWithBody(server string, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader) (*http.Request, error) { var err error var pathParam0 string @@ -479,7 +509,7 @@ func NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityI return nil, err } - operationPath := fmt.Sprintf("/api/v1/organizations/%s/projects/%s/identities/%s/physicalNetworks", pathParam0, pathParam1, pathParam2) + operationPath := fmt.Sprintf("/api/v1/organizations/%s/projects/%s/identities/%s/physicalnetworks", pathParam0, pathParam1, pathParam2) if operationPath[0] == '/' { operationPath = "." + operationPath } @@ -499,6 +529,116 @@ func NewPostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityI return req, nil } +// NewDeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDRequest generates requests for DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID +func NewDeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDRequest(server string, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "organizationID", runtime.ParamLocationPath, organizationID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam2 string + + pathParam2, err = runtime.StyleParamWithLocation("simple", false, "identityID", runtime.ParamLocationPath, identityID) + if err != nil { + return nil, err + } + + var pathParam3 string + + pathParam3, err = runtime.StyleParamWithLocation("simple", false, "physicalNetworkID", runtime.ParamLocationPath, physicalNetworkID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v1/organizations/%s/projects/%s/identities/%s/physicalnetworks/%s", pathParam0, pathParam1, pathParam2, pathParam3) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDRequest generates requests for GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID +func NewGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDRequest(server string, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "organizationID", runtime.ParamLocationPath, organizationID) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "projectID", runtime.ParamLocationPath, projectID) + if err != nil { + return nil, err + } + + var pathParam2 string + + pathParam2, err = runtime.StyleParamWithLocation("simple", false, "identityID", runtime.ParamLocationPath, identityID) + if err != nil { + return nil, err + } + + var pathParam3 string + + pathParam3, err = runtime.StyleParamWithLocation("simple", false, "physicalNetworkID", runtime.ParamLocationPath, physicalNetworkID) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/api/v1/organizations/%s/projects/%s/identities/%s/physicalnetworks/%s", pathParam0, pathParam1, pathParam2, pathParam3) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewGetApiV1OrganizationsOrganizationIDRegionsRequest generates requests for GetApiV1OrganizationsOrganizationIDRegions func NewGetApiV1OrganizationsOrganizationIDRegionsRequest(server string, organizationID OrganizationIDParameter) (*http.Request, error) { var err error @@ -713,10 +853,16 @@ type ClientWithResponsesInterface interface { // GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDWithResponse request GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, reqEditors ...RequestEditorFn) (*GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDResponse, error) - // PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBodyWithResponse request with any body - PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBodyWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse, error) + // PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBodyWithResponse request with any body + PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBodyWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse, error) + + PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse, error) - PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse, error) + // DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse request + DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse, error) + + // GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse request + GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse, error) // GetApiV1OrganizationsOrganizationIDRegionsWithResponse request GetApiV1OrganizationsOrganizationIDRegionsWithResponse(ctx context.Context, organizationID OrganizationIDParameter, reqEditors ...RequestEditorFn) (*GetApiV1OrganizationsOrganizationIDRegionsResponse, error) @@ -835,7 +981,7 @@ func (r GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID return 0 } -type PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse struct { +type PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse struct { Body []byte HTTPResponse *http.Response JSON201 *PhysicalNetworkResponse @@ -846,7 +992,7 @@ type PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPh } // Status returns HTTPResponse.Status -func (r PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse) Status() string { +func (r PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse) Status() string { if r.HTTPResponse != nil { return r.HTTPResponse.Status } @@ -854,7 +1000,58 @@ func (r PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityI } // StatusCode returns HTTPResponse.StatusCode -func (r PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse) StatusCode() int { +func (r PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse struct { + Body []byte + HTTPResponse *http.Response + JSON400 *externalRef0.BadRequestResponse + JSON401 *externalRef0.UnauthorizedResponse + JSON403 *externalRef0.ForbiddenResponse + JSON500 *externalRef0.InternalServerErrorResponse +} + +// Status returns HTTPResponse.Status +func (r DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *PhysicalNetworkResponse + JSON400 *externalRef0.BadRequestResponse + JSON401 *externalRef0.UnauthorizedResponse + JSON403 *externalRef0.ForbiddenResponse + JSON500 *externalRef0.InternalServerErrorResponse +} + +// Status returns HTTPResponse.Status +func (r GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse) StatusCode() int { if r.HTTPResponse != nil { return r.HTTPResponse.StatusCode } @@ -1005,21 +1202,39 @@ func (c *ClientWithResponses) GetApiV1OrganizationsOrganizationIDProjectsProject return ParseGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDResponse(rsp) } -// PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBodyWithResponse request with arbitrary body returning *PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse -func (c *ClientWithResponses) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBodyWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse, error) { - rsp, err := c.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithBody(ctx, organizationID, projectID, identityID, contentType, body, reqEditors...) +// PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBodyWithResponse request with arbitrary body returning *PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse +func (c *ClientWithResponses) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBodyWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse, error) { + rsp, err := c.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithBody(ctx, organizationID, projectID, identityID, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse(rsp) +} + +func (c *ClientWithResponses) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse, error) { + rsp, err := c.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(ctx, organizationID, projectID, identityID, body, reqEditors...) if err != nil { return nil, err } - return ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse(rsp) + return ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse(rsp) } -func (c *ClientWithResponses) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, body PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody, reqEditors ...RequestEditorFn) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse, error) { - rsp, err := c.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(ctx, organizationID, projectID, identityID, body, reqEditors...) +// DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse request returning *DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse +func (c *ClientWithResponses) DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse, error) { + rsp, err := c.DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(ctx, organizationID, projectID, identityID, physicalNetworkID, reqEditors...) if err != nil { return nil, err } - return ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse(rsp) + return ParseDeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse(rsp) +} + +// GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse request returning *GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse +func (c *ClientWithResponses) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse(ctx context.Context, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter, reqEditors ...RequestEditorFn) (*GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse, error) { + rsp, err := c.GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(ctx, organizationID, projectID, identityID, physicalNetworkID, reqEditors...) + if err != nil { + return nil, err + } + return ParseGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse(rsp) } // GetApiV1OrganizationsOrganizationIDRegionsWithResponse request returning *GetApiV1OrganizationsOrganizationIDRegionsResponse @@ -1274,15 +1489,15 @@ func ParseGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentity return response, nil } -// ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse parses an HTTP response from a PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksWithResponse call -func ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse(rsp *http.Response) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse, error) { +// ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse parses an HTTP response from a PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksWithResponse call +func ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse(rsp *http.Response) (*PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) defer func() { _ = rsp.Body.Close() }() if err != nil { return nil, err } - response := &PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksResponse{ + response := &PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksResponse{ Body: bodyBytes, HTTPResponse: rsp, } @@ -1328,6 +1543,107 @@ func ParsePostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentit return response, nil } +// ParseDeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse parses an HTTP response from a DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse call +func ParseDeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse(rsp *http.Response) (*DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest externalRef0.BadRequestResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest externalRef0.UnauthorizedResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest externalRef0.ForbiddenResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest externalRef0.InternalServerErrorResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + +// ParseGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse parses an HTTP response from a GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDWithResponse call +func ParseGetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse(rsp *http.Response) (*GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkIDResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest PhysicalNetworkResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest externalRef0.BadRequestResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest externalRef0.UnauthorizedResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403: + var dest externalRef0.ForbiddenResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON403 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 500: + var dest externalRef0.InternalServerErrorResponse + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON500 = &dest + + } + + return response, nil +} + // ParseGetApiV1OrganizationsOrganizationIDRegionsResponse parses an HTTP response from a GetApiV1OrganizationsOrganizationIDRegionsWithResponse call func ParseGetApiV1OrganizationsOrganizationIDRegionsResponse(rsp *http.Response) (*GetApiV1OrganizationsOrganizationIDRegionsResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) diff --git a/pkg/openapi/router.go b/pkg/openapi/router.go index 1a03c51..55c7081 100644 --- a/pkg/openapi/router.go +++ b/pkg/openapi/router.go @@ -27,8 +27,14 @@ type ServerInterface interface { // (GET /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter) - // (POST /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalNetworks) - PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter) + // (POST /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks) + PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter) + + // (DELETE /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}) + DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter) + + // (GET /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}) + GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter) // (GET /api/v1/organizations/{organizationID}/regions) GetApiV1OrganizationsOrganizationIDRegions(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter) @@ -67,8 +73,18 @@ func (_ Unimplemented) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdent w.WriteHeader(http.StatusNotImplemented) } -// (POST /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalNetworks) -func (_ Unimplemented) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter) { +// (POST /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks) +func (_ Unimplemented) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter) { + w.WriteHeader(http.StatusNotImplemented) +} + +// (DELETE /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}) +func (_ Unimplemented) DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter) { + w.WriteHeader(http.StatusNotImplemented) +} + +// (GET /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}) +func (_ Unimplemented) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request, organizationID OrganizationIDParameter, projectID ProjectIDParameter, identityID IdentityIDParameter, physicalNetworkID PhysicalNetworkIDParameter) { w.WriteHeader(http.StatusNotImplemented) } @@ -258,8 +274,109 @@ func (siw *ServerInterfaceWrapper) GetApiV1OrganizationsOrganizationIDProjectsPr handler.ServeHTTP(w, r.WithContext(ctx)) } -// PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks operation middleware -func (siw *ServerInterfaceWrapper) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(w http.ResponseWriter, r *http.Request) { +// PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks operation middleware +func (siw *ServerInterfaceWrapper) PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + var err error + + // ------------- Path parameter "organizationID" ------------- + var organizationID OrganizationIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "organizationID", runtime.ParamLocationPath, chi.URLParam(r, "organizationID"), &organizationID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "organizationID", Err: err}) + return + } + + // ------------- Path parameter "projectID" ------------- + var projectID ProjectIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "projectID", runtime.ParamLocationPath, chi.URLParam(r, "projectID"), &projectID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "projectID", Err: err}) + return + } + + // ------------- Path parameter "identityID" ------------- + var identityID IdentityIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "identityID", runtime.ParamLocationPath, chi.URLParam(r, "identityID"), &identityID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "identityID", Err: err}) + return + } + + ctx = context.WithValue(ctx, Oauth2AuthenticationScopes, []string{}) + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks(w, r, organizationID, projectID, identityID) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + +// DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID operation middleware +func (siw *ServerInterfaceWrapper) DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + + var err error + + // ------------- Path parameter "organizationID" ------------- + var organizationID OrganizationIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "organizationID", runtime.ParamLocationPath, chi.URLParam(r, "organizationID"), &organizationID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "organizationID", Err: err}) + return + } + + // ------------- Path parameter "projectID" ------------- + var projectID ProjectIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "projectID", runtime.ParamLocationPath, chi.URLParam(r, "projectID"), &projectID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "projectID", Err: err}) + return + } + + // ------------- Path parameter "identityID" ------------- + var identityID IdentityIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "identityID", runtime.ParamLocationPath, chi.URLParam(r, "identityID"), &identityID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "identityID", Err: err}) + return + } + + // ------------- Path parameter "physicalNetworkID" ------------- + var physicalNetworkID PhysicalNetworkIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "physicalNetworkID", runtime.ParamLocationPath, chi.URLParam(r, "physicalNetworkID"), &physicalNetworkID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "physicalNetworkID", Err: err}) + return + } + + ctx = context.WithValue(ctx, Oauth2AuthenticationScopes, []string{}) + + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + siw.Handler.DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w, r, organizationID, projectID, identityID, physicalNetworkID) + })) + + for _, middleware := range siw.HandlerMiddlewares { + handler = middleware(handler) + } + + handler.ServeHTTP(w, r.WithContext(ctx)) +} + +// GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID operation middleware +func (siw *ServerInterfaceWrapper) GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w http.ResponseWriter, r *http.Request) { ctx := r.Context() var err error @@ -291,10 +408,19 @@ func (siw *ServerInterfaceWrapper) PostApiV1OrganizationsOrganizationIDProjectsP return } + // ------------- Path parameter "physicalNetworkID" ------------- + var physicalNetworkID PhysicalNetworkIDParameter + + err = runtime.BindStyledParameterWithLocation("simple", false, "physicalNetworkID", runtime.ParamLocationPath, chi.URLParam(r, "physicalNetworkID"), &physicalNetworkID) + if err != nil { + siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "physicalNetworkID", Err: err}) + return + } + ctx = context.WithValue(ctx, Oauth2AuthenticationScopes, []string{}) handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - siw.Handler.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks(w, r, organizationID, projectID, identityID) + siw.Handler.GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID(w, r, organizationID, projectID, identityID, physicalNetworkID) })) for _, middleware := range siw.HandlerMiddlewares { @@ -569,7 +695,13 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handl r.Get(options.BaseURL+"/api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}", wrapper.GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityID) }) r.Group(func(r chi.Router) { - r.Post(options.BaseURL+"/api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalNetworks", wrapper.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks) + r.Post(options.BaseURL+"/api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks", wrapper.PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks) + }) + r.Group(func(r chi.Router) { + r.Delete(options.BaseURL+"/api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}", wrapper.DeleteApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID) + }) + r.Group(func(r chi.Router) { + r.Get(options.BaseURL+"/api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}", wrapper.GetApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksPhysicalNetworkID) }) r.Group(func(r chi.Router) { r.Get(options.BaseURL+"/api/v1/organizations/{organizationID}/regions", wrapper.GetApiV1OrganizationsOrganizationIDRegions) diff --git a/pkg/openapi/schema.go b/pkg/openapi/schema.go index 1eb12f9..69078cd 100644 --- a/pkg/openapi/schema.go +++ b/pkg/openapi/schema.go @@ -19,96 +19,98 @@ import ( // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+x8+3PbOJL/v4Lid6tmt76irLct/bLnSWYyrs0kvsTJ3u0olwLJpogxCXABUI7G5f/9", - "Cg++SUmWPY+9TdVMxZLw6kZ349MP4N7xWZIyClQKZ3XvpJjjBCRw/YkEQCWRu6uX1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UA+3qGY3QHXyVvkR5hjX506g9yLR4yj", - "aJdGQMUACYm51MAdqI2747KTalpEj2ig55UoYUKixbQytuJZDHQjI8WtBH95rT84q8V04CSE5h/HHcyo", - "Zh/3OFOrewfH8dtQ59+OQQUNV+y+6SQ0kp5dVrl20aSCxGrV1B7EjG4U/D0c7m1M2jYJn7oyzD0+bSut", - "+bt7so2V7z9wu+xh1wDdpFcp/0Ycihs9Fu8cWlgfum1tyu8Mcp++IQdF42i9PFLP25q6xyOrXsF6Dv0s", - "p+pWTYN9v6+kx5sCIMBEe20TuxQN0/VlDBPNUL6y8Z1FWzLaGffmNFehmidHiNRkE+xpVpnQZv5ESyqF", - "qQNiFJCIWBZrw151G7SDYu7ZaL8+s8EbhTnSmPjEmMQIuMIfa9o1qTo7XQ08ctAizCEiIxCAEnuOVaZV", - "K6peofn4+vINAukP17QjQdLcuibXusTZrLHPoppfn66qp5hOM/fJLkqle1taqMJkZsewx7KqjLSJrdZ+", - "HF5woQrPFq4q5u8n88ZO1OcQfyPKqKEaooqNy9hgFw7O61L2AOGiKuVIiFsRuQ6cy5sObUf4wNqxXAws", - "7tOpxDhGl9dXpa3jgAMThr3jpjq75YTuS+nXEtiVn6ylYfqDBtQ42ySKTC1KOoCnoWPCtGtAJXyRexPn", - "x10hrWD/prSYnHmFg9cd9U09x0XRTpeVaLeqWuRXCktGbym7o43qqepH7WEF0PjZFDV0C9hTjtDeIMh9", - "a5fNJT5Tk9bFBkkSqJ+T5uJMDNLELozNcFZOgCW4qnlPtLSD68cYyY796jiNm006juXBIxVG68iwuhl1", - "aPVVAx+pgQKSbbfzKiDBVBI/j2k1XOnteh38//V6WPmn013uCu80jjgdCUk5FOG3fMri33zz2htSrW4/", - "oH+G0k4PoUc3H+227tHqSqVwl9zoy2d3EUO2XU29u/MntdLV482EneB4M9FXZ5VR8s/scLlVwgJd1XeQ", - "8iwNjqM8H/EA5bhOtx3+WLq7ar1qLD/Cmt3o0v7c8NgSonxRFvL/rKC0rn43ALuWml1TTHf1U0+1iQDH", - "MrJ1laYC0wMKIZEo5CxBWP1EA6wrI9e0WIGhu4bISx2QeNMZ5cXcI5JjvkMSb4yxUmvQYbq2PnYX113m", - "wpIP0V1h0R0oVBuqf8rzjBJvDnuDeiH5mJ+66T1UQyPx5nisqPjXAonawvoZJ3L3XrWz4StdxlsvKG6v", - "420K3AD/IlFvK3A9wFzBY11tXK931uIdszvzWIEtj9W/vGABtL78wGNn5URSpmJ1VqTVhhklt4xTV2dd", - "h4xvzsySz7aTs1p/5db4LNVkKeLVik4YU/ermWb9kynDJjRkbe680Alh67cGRPhsC3xnqhhYppNzAviW", - "WBtCZKzGrURk35mu700jBQT0/W594DgrZzQcD8c6xJkCxSlxVs50OBpOzSkYaf6e4ZScbce16Ig4u68/", - "XvNQuZvZJuNHTPEGgjIHaBcthghdFf0qnr4gdBNrq2mqBHH+jXX5TRKL+jBcU21/YpIQ5dHHWEjEcUAy", - "kUfJYQumtg5X7nyjGPCtvhRNKBIsMReJBMJbRgKBvGyj+q9pHYvbU17xegOyq8BdarxV3D0197D1bStc", - "fxVIjcFy2df3U16BvEzJx/HbKp/f1rhc8sppvNgxGY36VLdod9ZxZfth4MyO6drxzIbuOj7ctfNihO48", - "Pdy5/SLAw8CZH0Xsnrt1VYulYU+3rfrpk4l2Vx6u6oFIZZOzvmei9FBH6pIN8omz++Jppn87BXsmrg8O", - "du14SEuBnJR1HZsvNK5EGFG4q5Q00EbAqq7Z10wcVG1buSOu89U0dD1/lmrXL/mVl6vOms9WPbTsxfho", - "e7H7ai2OthbPpuNn9+Vzdg9FwKQDOL7U39cqbBQ8UJC6BOFYCOYT7XhoH5zItpSagZ4gp1f19/dq0jY5", - "vAWtR6f+JaVtNpod7tm6jfzbH2r/xgAtX2q1pu3RUOxEPRh9tbp/ZIx2Glo43KvrtdNnBIS1w+LscHbW", - "qHtH1nWI0HU7E8uh/KDDOfYhh/KZOcbXtKjiQpQFjSyGtREfX1++GSL0hkkwA+laoEIhi5RYXppAB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6eoafCKk7pES8HV4pV02/G/J", + "Pgdh1K4anCdFp6W2u2ry3RG4teehz6Pga987GM/69Oug2JZiOrlrPZV8ENQ9kLGfENA2Wfuq84nnPyfi", + "/QMA12dLVliyHbA3jbZE7JSYp8K9R4jL6FmfP+Pj7UMn63/L/yHourem6p29YBpASKgyPCatg9B15Tmz", + "NbA1x2mkVY1+wGyLYrbWH1PMlWwwOlzR74h+buEWb4t7M+Z1VeUZk43VI0SYqwCSlUGbMrsqMj9CWKxo", + "bdKY+TiGQZliMG/EfiMQB32TL0BezDylMBQdMwm2ZvE77Ed5dilSykcKxG5pqb7acaOBTu/aV4vKe5YD", + "U6+ZD2BrTKtv7AqG9PVMYW8zVFMj5bVfEROj2fCKigjz4lKkjDjL1hG6jbCEDXCUgB+prSaKZMVdevOK", + "D5a2V76RXs34WqlUU3NTFM09WCdaNjlKqTVf+XqsRvo/nxuxBDu5y/8hiPviUZh+h/cijtmtKB+wQiun", + "9QbNytGsnbOMBQjWVCtRTYYr+pO+jP7i4uqtZuPi2nnrSRslSxCHA0Qk8jlOBWKZRO6KYqFNeCYyHCMX", + "kdAUROknohi1l6UyGgzQLcf+TSF5VO1IwxAdUssEugUkJIljfblZbSrCNIghf/7QCBWOkaDsNozxzT58", + "kBcEdL7Oc6xQvLOn9F3zjI4Rlt437J/jvX8YAND+514eKd29L9e8sLbMPl5UhKx36Xqhlb1f61m5llAp", + "M4HAFG0pu1jojScQhO/tdo7h/+a/aPAVke8z+x7Ivn0XV3PuNVdkj2De6n3XQ3j3KbT4pdnMUWmN+sPW", + "z6z7+7Du/f3/BgAA//8jN0CpUG4AAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/pkg/openapi/server.spec.yaml b/pkg/openapi/server.spec.yaml index 5fab2d1..12cd2f0 100644 --- a/pkg/openapi/server.spec.yaml +++ b/pkg/openapi/server.spec.yaml @@ -177,7 +177,7 @@ paths: $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/notFoundResponse' '500': $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/internalServerErrorResponse' - /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalNetworks: + /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks: description: |- Manages physical networks. Physical networks are networks that may be required for baremetal node provisioning e.g. a VLAN. Note that only a single provider network is currently @@ -187,7 +187,7 @@ paths: - $ref: '#/components/parameters/projectIDParameter' - $ref: '#/components/parameters/identityIDParameter' post: - description: Create a new provider network. + description: Create a new physical network. security: - oauth2Authentication: [] requestBody: @@ -203,6 +203,46 @@ paths: $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/forbiddenResponse' '500': $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/internalServerErrorResponse' + /api/v1/organizations/{organizationID}/projects/{projectID}/identities/{identityID}/physicalnetworks/{physicalNetworkID}: + description: |- + Manages physical networks. Physical networks are networks that may be required for + baremetal node provisioning e.g. a VLAN. Note that only a single provider network is currently + supported per identity, as identities are intended to exist per piece of infrastructure. + parameters: + - $ref: '#/components/parameters/organizationIDParameter' + - $ref: '#/components/parameters/projectIDParameter' + - $ref: '#/components/parameters/identityIDParameter' + - $ref: '#/components/parameters/physicalNetworkIDParameter' + get: + description: Get a phyiscal network. + security: + - oauth2Authentication: [] + responses: + '200': + $ref: '#/components/responses/physicalNetworkResponse' + '400': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/badRequestResponse' + '401': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/unauthorizedResponse' + '403': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/forbiddenResponse' + '500': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/internalServerErrorResponse' + delete: + description: Delete a new physical network. + security: + - oauth2Authentication: [] + responses: + '202': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/acceptedResponse' + '400': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/badRequestResponse' + '401': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/unauthorizedResponse' + '403': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/forbiddenResponse' + '500': + $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/responses/internalServerErrorResponse' components: parameters: organizationIDParameter: @@ -234,6 +274,13 @@ components: required: true schema: $ref: '#/components/schemas/kubernetesNameParameter' + physicalNetworkIDParameter: + name: physicalNetworkID + in: path + description: The physical network identifier. + required: true + schema: + $ref: '#/components/schemas/kubernetesNameParameter' schemas: kubernetesNameParameter: description: A Kubernetes name. Must be a valid DNS containing only lower case characters, numbers or hyphens, start and end with a character or number, and be at most 63 characters in length. diff --git a/pkg/openapi/types.go b/pkg/openapi/types.go index cd9a2ba..1fbf589 100644 --- a/pkg/openapi/types.go +++ b/pkg/openapi/types.go @@ -290,6 +290,9 @@ type IdentityIDParameter = KubernetesNameParameter // OrganizationIDParameter defines model for organizationIDParameter. type OrganizationIDParameter = string +// PhysicalNetworkIDParameter A Kubernetes name. Must be a valid DNS containing only lower case characters, numbers or hyphens, start and end with a character or number, and be at most 63 characters in length. +type PhysicalNetworkIDParameter = KubernetesNameParameter + // ProjectIDParameter A Kubernetes name. Must be a valid DNS containing only lower case characters, numbers or hyphens, start and end with a character or number, and be at most 63 characters in length. type ProjectIDParameter = KubernetesNameParameter @@ -326,5 +329,5 @@ type PhysicalNetworkRequest = PhysicalNetworkWrite // PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesJSONRequestBody defines body for PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentities for application/json ContentType. type PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesJSONRequestBody = IdentityWrite -// PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody defines body for PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworks for application/json ContentType. -type PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalNetworksJSONRequestBody = PhysicalNetworkWrite +// PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody defines body for PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworks for application/json ContentType. +type PostApiV1OrganizationsOrganizationIDProjectsProjectIDIdentitiesIdentityIDPhysicalnetworksJSONRequestBody = PhysicalNetworkWrite diff --git a/pkg/providers/allocation/vlan/vlan.go b/pkg/providers/allocation/vlan/vlan.go new file mode 100644 index 0000000..11a1fec --- /dev/null +++ b/pkg/providers/allocation/vlan/vlan.go @@ -0,0 +1,174 @@ +/* +Copyright 2024 the Unikorn Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package vlan + +import ( + "context" + "errors" + "fmt" + "slices" + + unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" + + kerrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var ( + ErrAllocation = errors.New("allocation failure") +) + +type Allocator struct { + client client.Client + namespace string + name string + spec *unikornv1.VLANSpec +} + +func New(client client.Client, namespace, name string, spec *unikornv1.VLANSpec) *Allocator { + return &Allocator{ + client: client, + namespace: namespace, + spec: spec, + } +} + +func (a *Allocator) allocatable() [4096]bool { + var table [4096]bool + + if a.spec == nil { + for i := 1; i < 4095; i++ { + table[i] = true + } + + return table + } + + for _, segment := range a.spec.Segments { + for i := segment.StartID; i <= segment.EndID; i++ { + table[i] = true + } + } + + return table +} + +func (a *Allocator) getVLANAllocation(ctx context.Context) (*unikornv1.VLANAllocation, error) { + allocation := &unikornv1.VLANAllocation{} + + if err := a.client.Get(ctx, client.ObjectKey{Namespace: a.namespace, Name: a.name}, allocation); err != nil { + return nil, err + } + + return allocation, nil +} + +func (a *Allocator) getOrCreateVLANAllocation(ctx context.Context) (*unikornv1.VLANAllocation, bool, error) { + create := false + + allocation, err := a.getVLANAllocation(ctx) + if err != nil { + if !kerrors.IsNotFound(err) { + return nil, false, err + } + + allocation = &unikornv1.VLANAllocation{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: a.namespace, + Name: a.name, + }, + } + + create = true + } + + return allocation, create, nil +} + +func (a *Allocator) Allocate(ctx context.Context, physicalNetworkID string) (int, error) { + allocation, create, err := a.getOrCreateVLANAllocation(ctx) + if err != nil { + return -1, err + } + + allocatable := a.allocatable() + + // Do an exhaustive search through all allocatable VLAN IDs... + // TODO: this is a O(n^2) problem, admitedly bounded. + for id := 1; id < 4095; id++ { + if !allocatable[id] { + continue + } + + // If there is already an allocation for that ID keep going.... + callback := func(allocation unikornv1.VLANAllocationEntry) bool { + return allocation.ID == id + } + + if index := slices.IndexFunc(allocation.Spec.Allocations, callback); index >= 0 { + continue + } + + // Perform an atomic update of the allocation table. + allocation.Spec.Allocations = append(allocation.Spec.Allocations, unikornv1.VLANAllocationEntry{ + ID: id, + PhysicalNetworkID: physicalNetworkID, + }) + + if create { + if err := a.client.Create(ctx, allocation); err != nil { + return -1, err + } + + return id, nil + } + + if err := a.client.Update(ctx, allocation); err != nil { + return -1, err + } + + return id, nil + } + + return -1, fmt.Errorf("%w: vlan ids exhausted", ErrAllocation) +} + +func (a *Allocator) Free(ctx context.Context, id int) error { + allocation, err := a.getVLANAllocation(ctx) + if err != nil { + return err + } + + allocationsLength := len(allocation.Spec.Allocations) + + callback := func(allocation unikornv1.VLANAllocationEntry) bool { + return allocation.ID == id + } + + allocation.Spec.Allocations = slices.DeleteFunc(allocation.Spec.Allocations, callback) + + if len(allocation.Spec.Allocations) != allocationsLength-1 { + return fmt.Errorf("%w: vlan id %d not allocated exactly once", ErrAllocation, id) + } + + if err := a.client.Update(ctx, allocation); err != nil { + return err + } + + return nil +} diff --git a/pkg/providers/interfaces.go b/pkg/providers/interfaces.go index 2770504..42fbbe4 100644 --- a/pkg/providers/interfaces.go +++ b/pkg/providers/interfaces.go @@ -20,7 +20,6 @@ import ( "context" unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" - "github.com/unikorn-cloud/region/pkg/openapi" ) // Providers are expected to provide a provider agnostic manner. @@ -37,8 +36,10 @@ type Provider interface { CreateIdentity(ctx context.Context, identity *unikornv1.Identity) error // DeleteIdentity cleans up an identity for cloud infrastructure. DeleteIdentity(ctx context.Context, identity *unikornv1.Identity) error - // CreatePhysicalNetwork create a new physical network. - CreatePhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, request *openapi.PhysicalNetworkWrite) (*unikornv1.PhysicalNetwork, error) + // CreatePhysicalNetwork creates a new physical network. + CreatePhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, physicalNetwork *unikornv1.PhysicalNetwork) error + // DeletePhysicalNetwork deletes a physical network. + DeletePhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, physicalNetwork *unikornv1.PhysicalNetwork) error // ListExternalNetworks returns a list of external networks if the platform // supports such a concept. ListExternalNetworks(ctx context.Context) (ExternalNetworks, error) diff --git a/pkg/providers/openstack/network.go b/pkg/providers/openstack/network.go index c4ab69f..7bc84b2 100644 --- a/pkg/providers/openstack/network.go +++ b/pkg/providers/openstack/network.go @@ -47,10 +47,13 @@ var ( // NetworkClient wraps the generic client because gophercloud is unsafe. type NetworkClient struct { + // client is a network client scoped as per the provider given + // during initialization. client *gophercloud.ServiceClient - + // options are optional configuration about the network service. options *unikornv1.RegionOpenstackNetworkSpec - + // externalNetworkCache provides caching to avoid having to talk to + // OpenStack. externalNetworkCache *cache.TimeoutCache[[]networks.Network] } @@ -147,43 +150,12 @@ func (c *NetworkClient) ExternalNetworks(ctx context.Context) ([]networks.Networ return result, nil } -// AllocateVLAN does exactly that using configured ID ranges and existing networks. -func (c *NetworkClient) AllocateVLAN(ctx context.Context) (int, error) { - allocatable := make([]bool, 4096) - - // If no configuration is given, own all of the IDs. If there are a list - // of segments, only allow those. - if c.options == nil || c.options.ProviderNetworks == nil || c.options.ProviderNetworks.VLAN == nil || c.options.ProviderNetworks.VLAN.Segments == nil { - for i := 1; i < 4096; i++ { - allocatable[i] = true - } - } else { - for _, segment := range c.options.ProviderNetworks.VLAN.Segments { - for i := segment.StartID; i < segment.EndID+1; i++ { - allocatable[i] = true - } - } - } - - // TODO: Next remove the ones we know are already allocated. - for i := range allocatable { - if allocatable[i] { - return i, nil - } - } - - return -1, ErrUnsufficentResource -} - // CreateVLANProviderNetwork creates a VLAN provider network for a project. -func (c *NetworkClient) CreateVLANProviderNetwork(ctx context.Context, name string, projectID string) (int, *networks.Network, error) { +// This requires https://github.com/unikorn-cloud/python-unikorn-openstack-policy +// to be installed, see the README for further details on how this has to work. +func (c *NetworkClient) CreateVLANProviderNetwork(ctx context.Context, name string, projectID string, vlanID int) (*networks.Network, error) { if c.options == nil || c.options.ProviderNetworks == nil || c.options.ProviderNetworks.PhysicalNetwork == nil { - return -1, nil, ErrConfiguration - } - - vlanID, err := c.AllocateVLAN(ctx) - if err != nil { - return -1, nil, err + return nil, ErrConfiguration } tracer := otel.GetTracerProvider().Tracer(constants.Application) @@ -208,8 +180,21 @@ func (c *NetworkClient) CreateVLANProviderNetwork(ctx context.Context, name stri network, err := networks.Create(ctx, c.client, opts).Extract() if err != nil { - return -1, nil, err + return nil, err } - return vlanID, network, nil + return network, nil +} + +func (c *NetworkClient) DeleteVLANProviderNetwork(ctx context.Context, id string) error { + if c.options == nil || c.options.ProviderNetworks == nil || c.options.ProviderNetworks.PhysicalNetwork == nil { + return ErrConfiguration + } + + tracer := otel.GetTracerProvider().Tracer(constants.Application) + + _, span := tracer.Start(ctx, "DELETE /network/v2.0/networks", trace.WithSpanKind(trace.SpanKindClient)) + defer span.End() + + return networks.Delete(ctx, c.client, id).ExtractErr() } diff --git a/pkg/providers/openstack/network_test.go b/pkg/providers/openstack/network_test.go deleted file mode 100644 index fa871a4..0000000 --- a/pkg/providers/openstack/network_test.go +++ /dev/null @@ -1,71 +0,0 @@ -/* -Copyright 2024 the Unikorn Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package openstack_test - -import ( - "context" - "testing" - - "github.com/stretchr/testify/require" - - unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" - "github.com/unikorn-cloud/region/pkg/providers/openstack" -) - -func TestVLANAllocateRanges(t *testing.T) { - tests := []struct { - name string - options *unikornv1.RegionOpenstackNetworkSpec - fail bool - expectedID int - }{ - { - name: "DefaultRange", - expectedID: 1, - }, - { - name: "SingleSegment", - options: &unikornv1.RegionOpenstackNetworkSpec{ - ProviderNetworks: &unikornv1.ProviderNetworks{ - VLAN: &unikornv1.VLANSpec{ - Segments: []unikornv1.VLANSegment{ - { - StartID: 100, - EndID: 200, - }, - }, - }, - }, - }, - expectedID: 100, - }, - } - - for _, test := range tests { - t.Run(t.Name()+"_"+test.name, func(t *testing.T) { - client := openstack.NewTestNetworkClient(test.options) - - id, err := client.AllocateVLAN(context.Background()) - if err != nil { - require.True(t, test.fail) - return - } - - require.Equal(t, test.expectedID, id) - }) - } -} diff --git a/pkg/providers/openstack/provider.go b/pkg/providers/openstack/provider.go index dd88e70..845055a 100644 --- a/pkg/providers/openstack/provider.go +++ b/pkg/providers/openstack/provider.go @@ -29,12 +29,10 @@ import ( "github.com/gophercloud/utils/openstack/clientconfig" coreconstants "github.com/unikorn-cloud/core/pkg/constants" - "github.com/unikorn-cloud/core/pkg/server/conversion" - "github.com/unikorn-cloud/identity/pkg/middleware/authorization" unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" "github.com/unikorn-cloud/region/pkg/constants" - "github.com/unikorn-cloud/region/pkg/openapi" "github.com/unikorn-cloud/region/pkg/providers" + "github.com/unikorn-cloud/region/pkg/providers/allocation/vlan" corev1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" @@ -51,6 +49,14 @@ var ( ErrKeyUndefined = errors.New("a required key was not defined") ) +type providerCredentials struct { + endpoint string + domainID string + projectID string + userID string + password string +} + type Provider struct { // client is Kubernetes client. client client.Client @@ -61,10 +67,14 @@ type Provider struct { // secret is the current region secret. secret *corev1.Secret - domainID string - projectID string - userID string - password string + // credentials hold cloud identity information. + credentials *providerCredentials + + // vlan allocation table. + // NOTE: this can only be used by a single client unless it's moved + // into a Kubernetes resource of some variety to gain speculative locking + // powers. + vlanAllocator *vlan.Allocator // DO NOT USE DIRECTLY, CALL AN ACCESSOR. _identity *IdentityClient @@ -77,11 +87,24 @@ type Provider struct { var _ providers.Provider = &Provider{} -func New(client client.Client, region *unikornv1.Region) *Provider { - return &Provider{ - client: client, - region: region, +func New(ctx context.Context, cli client.Client, region *unikornv1.Region) (*Provider, error) { + var vlanSpec *unikornv1.VLANSpec + + if region.Spec.Openstack != nil && region.Spec.Openstack.Network != nil && region.Spec.Openstack.Network.ProviderNetworks != nil { + vlanSpec = region.Spec.Openstack.Network.ProviderNetworks.VLAN } + + p := &Provider{ + client: cli, + region: region, + vlanAllocator: vlan.New(cli, region.Namespace, "openstack-region-provider", vlanSpec), + } + + if err := p.serviceClientRefresh(ctx); err != nil { + return nil, err + } + + return p, nil } // serviceClientRefresh updates clients if they need to e.g. in the event @@ -147,15 +170,25 @@ func (p *Provider) serviceClientRefresh(ctx context.Context) error { return fmt.Errorf("%w: project-id", ErrKeyUndefined) } - // 'Regular' client calls to APIs for Nova, Glance etc. must to be project-scoped - providerClient := NewPasswordProvider(region.Spec.Openstack.Endpoint, string(userID), string(password), string(projectID)) + credentials := &providerCredentials{ + endpoint: region.Spec.Openstack.Endpoint, + domainID: string(domainID), + projectID: string(projectID), + userID: string(userID), + password: string(password), + } - // Identity client is scoped to a domain to use the manager role + // The identity client needs to have "manager" powers, so it create projects and + // users within a domain without full admin. identity, err := NewIdentityClient(ctx, NewDomainScopedPasswordProvider(region.Spec.Openstack.Endpoint, string(userID), string(password), string(domainID))) if err != nil { return err } + // Everything else gets a default view when bound to a project as a "member". + // Sadly, domain scoped accesses do not work by default any longer. + providerClient := NewPasswordProvider(region.Spec.Openstack.Endpoint, string(userID), string(password), string(projectID)) + compute, err := NewComputeClient(ctx, providerClient, region.Spec.Openstack.Compute) if err != nil { return err @@ -174,12 +207,7 @@ func (p *Provider) serviceClientRefresh(ctx context.Context) error { // Save the current configuration for checking next time. p.region = region p.secret = secret - - p.domainID = string(domainID) - p.projectID = string(projectID) - - p.userID = string(userID) - p.password = string(password) + p.credentials = credentials // Seve the clients p._identity = identity @@ -396,7 +424,7 @@ func (p *Provider) provisionUser(ctx context.Context, identityService *IdentityC name := identityResourceName(identity) password := string(uuid.NewUUID()) - user, err := identityService.CreateUser(ctx, p.domainID, name, password) + user, err := identityService.CreateUser(ctx, p.credentials.domainID, name, password) if err != nil { return err } @@ -417,7 +445,7 @@ func (p *Provider) provisionProject(ctx context.Context, identityService *Identi name := identityResourceName(identity) - project, err := identityService.CreateProject(ctx, p.domainID, name, projectTags(identity)) + project, err := identityService.CreateProject(ctx, p.credentials.domainID, name, projectTags(identity)) if err != nil { return err } @@ -439,9 +467,19 @@ func roleNameToID(roles []roles.Role, name string) (string, error) { return "", fmt.Errorf("%w: role %s", ErrResourceNotFound, name) } -// getRequiredRoles returns the roles required for a user to create, manage and delete +// getRequiredProjectManagerRoles returns the roles required for a manager to create, manage +// and delete things like provider networks to support baremetal. +func (p *Provider) getRequiredProjectManagerRoles() []string { + defaultRoles := []string{ + "manager", + } + + return defaultRoles +} + +// getRequiredProjectUserRoles returns the roles required for a user to create, manage and delete // a cluster. -func (p *Provider) getRequiredRoles() []string { +func (p *Provider) getRequiredProjectUserRoles() []string { if p.region.Spec.Openstack.Identity != nil && len(p.region.Spec.Openstack.Identity.ClusterRoles) > 0 { return p.region.Spec.Openstack.Identity.ClusterRoles } @@ -457,19 +495,19 @@ func (p *Provider) getRequiredRoles() []string { // provisionProjectRoles creates a binding between our service account and the project // with the required roles to provision an application credential that will allow cluster // creation, deletion and life-cycle management. -func (p *Provider) provisionProjectRoles(ctx context.Context, identityService *IdentityClient, identity *unikornv1.OpenstackIdentity) error { +func (p *Provider) provisionProjectRoles(ctx context.Context, identityService *IdentityClient, identity *unikornv1.OpenstackIdentity, userID string, rolesGetter func() []string) error { allRoles, err := identityService.ListRoles(ctx) if err != nil { return err } - for _, name := range p.getRequiredRoles() { + for _, name := range rolesGetter() { roleID, err := roleNameToID(allRoles, name) if err != nil { return err } - if err := identityService.CreateRoleAssignment(ctx, *identity.Spec.UserID, *identity.Spec.ProjectID, roleID); err != nil { + if err := identityService.CreateRoleAssignment(ctx, userID, *identity.Spec.ProjectID, roleID); err != nil { return err } } @@ -492,7 +530,7 @@ func (p *Provider) provisionApplicationCredential(ctx context.Context, identity name := identityResourceName(identity) - appcred, err := identityService.CreateApplicationCredential(ctx, *identity.Spec.UserID, name, "IaaS lifecycle management", p.getRequiredRoles()) + appcred, err := identityService.CreateApplicationCredential(ctx, *identity.Spec.UserID, name, "IaaS lifecycle management", p.getRequiredProjectUserRoles()) if err != nil { return err } @@ -534,29 +572,6 @@ func (p *Provider) createClientConfig(identity *unikornv1.OpenstackIdentity) err return nil } -func convertTag(in openapi.Tag) unikornv1.Tag { - out := unikornv1.Tag{ - Name: in.Name, - Value: in.Value, - } - - return out -} - -func convertTagList(in *openapi.TagList) unikornv1.TagList { - if in == nil { - return nil - } - - out := make(unikornv1.TagList, len(*in)) - - for i := range *in { - out[i] = convertTag((*in)[i]) - } - - return out -} - func (p *Provider) createIdentityServerGroup(ctx context.Context, identity *unikornv1.OpenstackIdentity) error { if identity.Spec.ServerGroupID != nil { return nil @@ -658,6 +673,14 @@ func (p *Provider) CreateIdentity(ctx context.Context, identity *unikornv1.Ident return err } + // Grant the "manager" role on the project for unikorn's user. Sadly when provisioning + // resources, most services can only infer the project ID from the token, and not any + // of the heirarchy, so we cannot define policy rules for a domain manager in the same + // way as can be done for the identity service. + if err := p.provisionProjectRoles(ctx, identityService, openstackIdentity, p.credentials.userID, p.getRequiredProjectManagerRoles); err != nil { + return err + } + // You MUST provision a new user, if we rotate a password, any application credentials // hanging off it will stop working, i.e. doing that to the unikorn management user // will be pretty catastrophic for all clusters in the region. @@ -667,7 +690,7 @@ func (p *Provider) CreateIdentity(ctx context.Context, identity *unikornv1.Ident // Give the user only what permissions they need to provision a cluster and // manage it during its lifetime. - if err := p.provisionProjectRoles(ctx, identityService, openstackIdentity); err != nil { + if err := p.provisionProjectRoles(ctx, identityService, openstackIdentity, *openstackIdentity.Spec.UserID, p.getRequiredProjectUserRoles); err != nil { return err } @@ -740,50 +763,167 @@ func (p *Provider) DeleteIdentity(ctx context.Context, identity *unikornv1.Ident return nil } +func (p *Provider) GetOpenstackPhysicalNetwork(ctx context.Context, physicalNetwork *unikornv1.PhysicalNetwork) (*unikornv1.OpenstackPhysicalNetwork, error) { + var result unikornv1.OpenstackPhysicalNetwork + + if err := p.client.Get(ctx, client.ObjectKey{Namespace: physicalNetwork.Namespace, Name: physicalNetwork.Name}, &result); err != nil { + return nil, err + } + + return &result, nil +} + +func (p *Provider) GetOrCreateOpenstackPhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, physicalNetwork *unikornv1.PhysicalNetwork) (*unikornv1.OpenstackPhysicalNetwork, bool, error) { + create := false + + openstackPhysicalNetwork, err := p.GetOpenstackPhysicalNetwork(ctx, physicalNetwork) + if err != nil { + if !kerrors.IsNotFound(err) { + return nil, false, err + } + + openstackPhysicalNetwork = &unikornv1.OpenstackPhysicalNetwork{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: physicalNetwork.Namespace, + Name: physicalNetwork.Name, + Labels: map[string]string{ + constants.IdentityLabel: identity.Name, + constants.PhysicalNetworkLabel: physicalNetwork.Name, + }, + Annotations: physicalNetwork.Annotations, + }, + } + + for k, v := range physicalNetwork.Labels { + openstackPhysicalNetwork.Labels[k] = v + } + + create = true + } + + return openstackPhysicalNetwork, create, nil +} + +func (p *Provider) allocateVLAN(ctx context.Context, physicalNetwork *unikornv1.OpenstackPhysicalNetwork) error { + if physicalNetwork.Spec.VlanID != nil { + return nil + } + + vlanID, err := p.vlanAllocator.Allocate(ctx, physicalNetwork.Name) + if err != nil { + return err + } + + physicalNetwork.Spec.VlanID = &vlanID + + return nil +} + +func (p *Provider) createPhysicalNetwork(ctx context.Context, identity *unikornv1.OpenstackIdentity, physicalNetwork *unikornv1.OpenstackPhysicalNetwork) error { + if physicalNetwork.Spec.ID != nil { + return nil + } + + // Rescope to the project... + providerClient := NewPasswordProvider(p.region.Spec.Openstack.Endpoint, p.credentials.userID, p.credentials.password, *identity.Spec.ProjectID) + + networkService, err := NewNetworkClient(ctx, providerClient, p.region.Spec.Openstack.Network) + if err != nil { + return err + } + + providerNetwork, err := networkService.CreateVLANProviderNetwork(ctx, "cluster-provider-network", *identity.Spec.ProjectID, *physicalNetwork.Spec.VlanID) + if err != nil { + return err + } + + physicalNetwork.Spec.ID = &providerNetwork.ID + + return nil +} + // CreatePhysicalNetwork creates a physical network for an identity. -func (p *Provider) CreatePhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, request *openapi.PhysicalNetworkWrite) (*unikornv1.PhysicalNetwork, error) { +func (p *Provider) CreatePhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, physicalNetwork *unikornv1.PhysicalNetwork) error { openstackIdentity, err := p.GetOpenstackIdentity(ctx, identity) if err != nil { - return nil, err + return err } - networkService, err := p.network(ctx) + openstackPhysicalNetwork, create, err := p.GetOrCreateOpenstackPhysicalNetwork(ctx, identity, physicalNetwork) if err != nil { - return nil, err + return err + } + + record := func() { + log := log.FromContext(ctx) + + if create { + if err := p.client.Create(ctx, openstackPhysicalNetwork); err != nil { + log.Error(err, "failed to create openstack physical network") + } + + return + } + + if err := p.client.Update(ctx, openstackPhysicalNetwork); err != nil { + log.Error(err, "failed to update openstack physical network") + } + } + + defer record() + + if err := p.allocateVLAN(ctx, openstackPhysicalNetwork); err != nil { + return err } - vlanID, providerNetwork, err := networkService.CreateVLANProviderNetwork(ctx, "cluster-provider-network", *openstackIdentity.Spec.ProjectID) + if err := p.createPhysicalNetwork(ctx, openstackIdentity, openstackPhysicalNetwork); err != nil { + return err + } + + return nil +} + +// DeletePhysicalNetwork deletes a physical network. +func (p *Provider) DeletePhysicalNetwork(ctx context.Context, identity *unikornv1.Identity, physicalNetwork *unikornv1.PhysicalNetwork) error { + openstackIdentity, err := p.GetOpenstackIdentity(ctx, identity) if err != nil { - return nil, err + return err } - userinfo, err := authorization.UserinfoFromContext(ctx) + openstackPhysicalNetwork, err := p.GetOpenstackPhysicalNetwork(ctx, physicalNetwork) if err != nil { - return nil, err + if !kerrors.IsNotFound(err) { + return err + } + + return nil } - objectMeta := conversion.NewObjectMetadata(&request.Metadata, p.region.Namespace, userinfo.Sub) - objectMeta = objectMeta.WithOrganization(identity.Labels[coreconstants.OrganizationLabel]) - objectMeta = objectMeta.WithProject(identity.Labels[coreconstants.ProjectLabel]) - objectMeta = objectMeta.WithLabel(constants.RegionLabel, p.region.Name) - objectMeta = objectMeta.WithLabel(constants.IdentityLabel, identity.Name) + if openstackPhysicalNetwork.Spec.ID != nil { + // Rescope to the project... + providerClient := NewPasswordProvider(p.region.Spec.Openstack.Endpoint, p.credentials.userID, p.credentials.password, *openstackIdentity.Spec.ProjectID) - physicalNetwork := &unikornv1.PhysicalNetwork{ - ObjectMeta: objectMeta.Get(), - Spec: unikornv1.PhysicalNetworkSpec{ - Tags: convertTagList(request.Spec.Tags), - ProviderNetwork: &unikornv1.OpenstackProviderNetworkSpec{ - ID: providerNetwork.ID, - VlanID: vlanID, - }, - }, + networkService, err := NewNetworkClient(ctx, providerClient, p.region.Spec.Openstack.Network) + if err != nil { + return err + } + + if err := networkService.DeleteVLANProviderNetwork(ctx, *openstackPhysicalNetwork.Spec.ID); err != nil { + return err + } } - if err := p.client.Create(ctx, physicalNetwork); err != nil { - return nil, err + if openstackPhysicalNetwork.Spec.VlanID != nil { + if err := p.vlanAllocator.Free(ctx, *openstackPhysicalNetwork.Spec.VlanID); err != nil { + return err + } } - return physicalNetwork, nil + if err := p.client.Delete(ctx, openstackPhysicalNetwork); err != nil { + return err + } + + return nil } // ListExternalNetworks returns a list of external networks if the platform diff --git a/pkg/provisioners/managers/identity/provisioner.go b/pkg/provisioners/managers/identity/provisioner.go index 980134e..db0e7da 100644 --- a/pkg/provisioners/managers/identity/provisioner.go +++ b/pkg/provisioners/managers/identity/provisioner.go @@ -26,6 +26,12 @@ import ( unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" "github.com/unikorn-cloud/region/pkg/constants" "github.com/unikorn-cloud/region/pkg/handler/region" + + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/selection" + + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" ) // Provisioner encapsulates control plane provisioning. @@ -71,11 +77,48 @@ func (p *Provisioner) Provision(ctx context.Context) error { // Deprovision implements the Provision interface. func (p *Provisioner) Deprovision(ctx context.Context) error { + log := log.FromContext(ctx) + cli, err := coreclient.ProvisionerClientFromContext(ctx) if err != nil { return err } + identityRequirement, err := labels.NewRequirement(constants.IdentityLabel, selection.Equals, []string{p.identity.Name}) + if err != nil { + return err + } + + selector := labels.NewSelector() + selector = selector.Add(*identityRequirement) + + // Block identity deletion until all owned resources are deleted, we cannot guarantee + // the underlying cloud implementation will not just orphan them and leak resources. + var physicalNetworks unikornv1.PhysicalNetworkList + + if err := cli.List(ctx, &physicalNetworks, &client.ListOptions{Namespace: p.identity.Namespace, LabelSelector: selector}); err != nil { + return err + } + + if len(physicalNetworks.Items) != 0 { + for i := range physicalNetworks.Items { + resource := &physicalNetworks.Items[i] + + if resource.DeletionTimestamp != nil { + log.Info("awaiting physical network deletion", "physical network", resource.Name) + continue + } + + log.Info("triggering physical network deletion", "physical network", resource.Name) + + if err := cli.Delete(ctx, resource); err != nil { + return err + } + } + + return provisioners.ErrYield + } + provider, err := region.NewClient(cli, p.identity.Namespace).Provider(ctx, p.identity.Labels[constants.RegionLabel]) if err != nil { return err diff --git a/pkg/provisioners/managers/physicalnetwork/provisioner.go b/pkg/provisioners/managers/physicalnetwork/provisioner.go new file mode 100644 index 0000000..ed24939 --- /dev/null +++ b/pkg/provisioners/managers/physicalnetwork/provisioner.go @@ -0,0 +1,140 @@ +/* +Copyright 2024 the Unikorn Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package physicalnetwork + +import ( + "context" + "errors" + "fmt" + + unikornv1core "github.com/unikorn-cloud/core/pkg/apis/unikorn/v1alpha1" + coreclient "github.com/unikorn-cloud/core/pkg/client" + coremanager "github.com/unikorn-cloud/core/pkg/manager" + "github.com/unikorn-cloud/core/pkg/provisioners" + unikornv1 "github.com/unikorn-cloud/region/pkg/apis/unikorn/v1alpha1" + "github.com/unikorn-cloud/region/pkg/constants" + "github.com/unikorn-cloud/region/pkg/handler/region" + + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/log" +) + +var ( + ErrResouceDependency = errors.New("resource dependency error") +) + +// Provisioner encapsulates control plane provisioning. +type Provisioner struct { + provisioners.Metadata + + // physicalNetwork is the physicalNetwork we're provisioning. + physicalNetwork *unikornv1.PhysicalNetwork +} + +// New returns a new initialized provisioner object. +func New(_ coremanager.ControllerOptions) provisioners.ManagerProvisioner { + return &Provisioner{ + physicalNetwork: &unikornv1.PhysicalNetwork{}, + } +} + +// Ensure the ManagerProvisioner interface is implemented. +var _ provisioners.ManagerProvisioner = &Provisioner{} + +func (p *Provisioner) Object() unikornv1core.ManagableResourceInterface { + return p.physicalNetwork +} + +func (p *Provisioner) getIdentity(ctx context.Context, cli client.Client) (*unikornv1.Identity, error) { + identity := &unikornv1.Identity{} + + if err := cli.Get(ctx, client.ObjectKey{Namespace: p.physicalNetwork.Namespace, Name: p.physicalNetwork.Labels[constants.IdentityLabel]}, identity); err != nil { + return nil, err + } + + return identity, nil +} + +// Provision implements the Provision interface. +func (p *Provisioner) Provision(ctx context.Context) error { + log := log.FromContext(ctx) + + cli, err := coreclient.ProvisionerClientFromContext(ctx) + if err != nil { + return err + } + + provider, err := region.NewClient(cli, p.physicalNetwork.Namespace).Provider(ctx, p.physicalNetwork.Labels[constants.RegionLabel]) + if err != nil { + return err + } + + identity, err := p.getIdentity(ctx, cli) + if err != nil { + return err + } + + // Inhibit provisioning until the identity is ready, as we may need the identity information + // to create the physical network e.g. the project ID in the case of OpenStack. + // TODO: the kinda mirrors what the Kubernetes service is doing when waiting for an identity + // and physical network, perhaps we can formalize and share the concepts? + status, err := identity.StatusConditionRead(unikornv1core.ConditionAvailable) + if err != nil { + log.Info("waiting for identity status update") + + return provisioners.ErrYield + } + + switch status.Reason { + case unikornv1core.ConditionReasonProvisioned: + break + case unikornv1core.ConditionReasonProvisioning: + return provisioners.ErrYield + default: + return fmt.Errorf("%w: identity in unexpected condition %v", ErrResouceDependency, status.Reason) + } + + if err := provider.CreatePhysicalNetwork(ctx, identity, p.physicalNetwork); err != nil { + return err + } + + return nil +} + +// Deprovision implements the Provision interface. +func (p *Provisioner) Deprovision(ctx context.Context) error { + cli, err := coreclient.ProvisionerClientFromContext(ctx) + if err != nil { + return err + } + + provider, err := region.NewClient(cli, p.physicalNetwork.Namespace).Provider(ctx, p.physicalNetwork.Labels[constants.RegionLabel]) + if err != nil { + return err + } + + identity, err := p.getIdentity(ctx, cli) + if err != nil { + return err + } + + if err := provider.DeletePhysicalNetwork(ctx, identity, p.physicalNetwork); err != nil { + return err + } + + return nil +}