From 231e410c66452c5b7196cfec3573ed9074820fb3 Mon Sep 17 00:00:00 2001 From: Simon Murray Date: Thu, 6 Jun 2024 14:44:21 +0100 Subject: [PATCH] Get Service Functional Test and get working the Helm deployment, and start to expand the API to be useful to the Kubernetes service. --- .../region.unikorn-cloud.org_regions.yaml | 2 +- charts/region/templates/_helpers.tpl | 14 +-- .../region-controller/clusterrole.yaml | 36 +------ .../region-controller/deployment.yaml | 1 + charts/region/templates/region.yaml | 2 +- pkg/apis/unikorn/v1alpha1/types.go | 2 +- pkg/handler/handler.go | 11 ++- pkg/handler/region/region.go | 23 ++++- pkg/openapi/schema.go | 93 ++++++++++--------- pkg/openapi/server.spec.yaml | 16 ++++ pkg/openapi/types.go | 17 ++++ pkg/server/options.go | 3 + pkg/server/server.go | 2 +- 13 files changed, 115 insertions(+), 107 deletions(-) diff --git a/charts/region/crds/region.unikorn-cloud.org_regions.yaml b/charts/region/crds/region.unikorn-cloud.org_regions.yaml index 3424ce3..2b3ea36 100644 --- a/charts/region/crds/region.unikorn-cloud.org_regions.yaml +++ b/charts/region/crds/region.unikorn-cloud.org_regions.yaml @@ -14,7 +14,7 @@ spec: listKind: RegionList plural: regions singular: region - scope: Cluster + scope: Namespaced versions: - additionalPrinterColumns: - jsonPath: .metadata.labels['unikorn-cloud\.org/name'] diff --git a/charts/region/templates/_helpers.tpl b/charts/region/templates/_helpers.tpl index 0fee57c..c17354c 100644 --- a/charts/region/templates/_helpers.tpl +++ b/charts/region/templates/_helpers.tpl @@ -72,20 +72,8 @@ Create the container images {{- end }} {{- end }} -{{- define "unikorn.clusterManagerControllerImage" -}} -{{- .Values.clusterManagerController.image | default (printf "%s/unikorn-cluster-manager-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} -{{- end }} - -{{- define "unikorn.clusterControllerImage" -}} -{{- .Values.clusterController.image | default (printf "%s/unikorn-cluster-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} -{{- end }} - -{{- define "unikorn.monitorImage" -}} -{{- .Values.monitor.image | default (printf "%s/unikorn-monitor:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} -{{- end }} - {{- define "unikorn.regionImage" -}} -{{- .Values.region.image | default (printf "%s/unikorn-region:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} +{{- .Values.region.image | default (printf "%s/unikorn-region-controller:%s" (include "unikorn.defaultRepositoryPath" .) (.Values.tag | default .Chart.Version)) }} {{- end }} {{/* diff --git a/charts/region/templates/region-controller/clusterrole.yaml b/charts/region/templates/region-controller/clusterrole.yaml index 67312a0..3ee069d 100644 --- a/charts/region/templates/region-controller/clusterrole.yaml +++ b/charts/region/templates/region-controller/clusterrole.yaml @@ -7,50 +7,16 @@ metadata: rules: # Orchestrate Unikorn resources (my job). - apiGroups: - - unikorn-cloud.org - resources: - - clustermanagers - - kubernetesclusters - verbs: - - create - - get - - list - - watch - - patch - - delete -- apiGroups: - - unikorn-cloud.org + - region.unikorn-cloud.org resources: - regions - - clustermanagerapplicationbundles - - kubernetesclusterapplicationbundles - - helmapplications verbs: - list - watch -# Find project namespaces -- apiGroups: - - "" - resources: - - namespaces - verbs: - - list - - watch -# Get secrets, ugh, for kubeconfigs. - apiGroups: - "" resources: - secrets - - services - verbs: - - get - - list - - watch -- apiGroups: - - "" - resources: - - events verbs: - - get - list - watch diff --git a/charts/region/templates/region-controller/deployment.yaml b/charts/region/templates/region-controller/deployment.yaml index 6a34a1a..d51e38f 100644 --- a/charts/region/templates/region-controller/deployment.yaml +++ b/charts/region/templates/region-controller/deployment.yaml @@ -18,6 +18,7 @@ spec: - name: unikorn-region image: {{ include "unikorn.regionImage" . }} args: + - --namespace={{ .Release.Namespace }} {{- with $cors := .Values.region.cors }} {{- range $origin := $cors.allowOrigin }} {{ printf "- --cors-allow-origin=%s" $origin | nindent 8 }} diff --git a/charts/region/templates/region.yaml b/charts/region/templates/region.yaml index ff8cd9b..0be1381 100644 --- a/charts/region/templates/region.yaml +++ b/charts/region/templates/region.yaml @@ -1,5 +1,5 @@ {{- range $region := .Values.regions }} -apiVersion: unikorn-cloud.org/v1alpha1 +apiVersion: region.unikorn-cloud.org/v1alpha1 kind: Region metadata: name: {{ include "resource.id" $region.name }} diff --git a/pkg/apis/unikorn/v1alpha1/types.go b/pkg/apis/unikorn/v1alpha1/types.go index 8b2aa3b..802facf 100644 --- a/pkg/apis/unikorn/v1alpha1/types.go +++ b/pkg/apis/unikorn/v1alpha1/types.go @@ -44,7 +44,7 @@ type RegionList struct { // about the provider for that region. // +genclient // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -// +kubebuilder:resource:scope=Cluster,categories=unikorn +// +kubebuilder:resource:scope=Namespaced,categories=unikorn // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="display name",type="string",JSONPath=".metadata.labels['unikorn-cloud\\.org/name']" // +kubebuilder:printcolumn:name="provider",type="string",JSONPath=".spec.provider" diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 3882c6d..c5bd30f 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -38,6 +38,9 @@ type Handler struct { // client gives cached access to Kubernetes. client client.Client + // namespace is the namespace we are running in. + namespace string + // options allows behaviour to be defined on the CLI. options *Options @@ -45,7 +48,7 @@ type Handler struct { authorizerOptions *oidc.Options } -func New(client client.Client, options *Options, authorizerOptions *oidc.Options) (*Handler, error) { +func New(client client.Client, namespace string, options *Options, authorizerOptions *oidc.Options) (*Handler, error) { h := &Handler{ client: client, options: options, @@ -65,7 +68,7 @@ func (h *Handler) setUncacheable(w http.ResponseWriter) { } func (h *Handler) GetApiV1Regions(w http.ResponseWriter, r *http.Request) { - result, err := region.NewClient(h.client).List(r.Context()) + result, err := region.NewClient(h.client, h.namespace).List(r.Context()) if err != nil { errors.HandleError(w, r, err) return @@ -76,7 +79,7 @@ func (h *Handler) GetApiV1Regions(w http.ResponseWriter, r *http.Request) { } func (h *Handler) GetApiV1RegionsRegionIDFlavors(w http.ResponseWriter, r *http.Request, regionID openapi.RegionIDParameter) { - provider, err := region.NewClient(h.client).Provider(r.Context(), regionID) + provider, err := region.NewClient(h.client, h.namespace).Provider(r.Context(), regionID) if err != nil { errors.HandleError(w, r, err) return @@ -113,7 +116,7 @@ func (h *Handler) GetApiV1RegionsRegionIDFlavors(w http.ResponseWriter, r *http. } func (h *Handler) GetApiV1RegionsRegionIDImages(w http.ResponseWriter, r *http.Request, regionID openapi.RegionIDParameter) { - provider, err := region.NewClient(h.client).Provider(r.Context(), regionID) + provider, err := region.NewClient(h.client, h.namespace).Provider(r.Context(), regionID) if err != nil { errors.HandleError(w, r, err) return diff --git a/pkg/handler/region/region.go b/pkg/handler/region/region.go index eda6e69..fe40121 100644 --- a/pkg/handler/region/region.go +++ b/pkg/handler/region/region.go @@ -40,13 +40,14 @@ var ( ) type Client struct { - client client.Client - // region string + client client.Client + namespace string } -func NewClient(client client.Client) *Client { +func NewClient(client client.Client, namespace string) *Client { return &Client{ - client: client, + client: client, + namespace: namespace, } } @@ -55,7 +56,7 @@ func NewClient(client client.Client) *Client { func (c *Client) list(ctx context.Context) (*unikornv1.RegionList, error) { var regions unikornv1.RegionList - if err := c.client.List(ctx, ®ions); err != nil { + if err := c.client.List(ctx, ®ions, &client.ListOptions{Namespace: c.namespace}); err != nil { return nil, err } @@ -110,9 +111,21 @@ func (c *Client) Provider(ctx context.Context, regionName string) (providers.Pro return provider, nil } +func convertRegionType(in unikornv1.Provider) openapi.RegionType { + switch in { + case unikornv1.ProviderOpenstack: + return openapi.Openstack + } + + return "" +} + func convert(in *unikornv1.Region) *openapi.RegionRead { out := &openapi.RegionRead{ Metadata: conversion.ResourceReadMetadata(in, coreopenapi.ResourceProvisioningStatusProvisioned), + Spec: openapi.RegionSpec{ + Type: convertRegionType(in.Spec.Provider), + }, } return out diff --git a/pkg/openapi/schema.go b/pkg/openapi/schema.go index 6ad04b8..f8049e7 100644 --- a/pkg/openapi/schema.go +++ b/pkg/openapi/schema.go @@ -19,52 +19,53 @@ import ( // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/+xa3Y/btrL/VwjeAr0XkOTv/dBLkZv09gYnbYJkm4dm9ywocWyxS5EqSXnXXfh/PxhS", - "smVbdpxtXw5w3lYSOZyP3wx/M95nmuuy0gqUszR9phUzrAQHxj8ZWAit3r750L7FlxxsbkTlhFY0pTcF", - "kLCMKFZCQiMq8H3FXEEjiu9ouhFEI2rgj1oY4DR1poaI2ryAkqHg7wzMaUr/a7BVaRC+2sFDnYFR4MD+", - "wkrY6rNer1GkrbSy4HXOGP8If9Rg3cfmNb7NtXKgHP7JqkqKnKH+g98tGvFM4YmVlfQrwRhtaEqFWjIp", - "+L0JwmgUvtzvmt98JZnmK9JsoetzrQpneRt2xX7sip0zIYGTsIn4I7z2EdGGOO//sJprsERpR9BaJtSt", - "YlJuVqDTyVyA5DZBFeeSLbWxL/HSl2eaV7Wl6TSiXNgHmo6HEV34V6OICk5Tes2u8ovJ5TCeDi9m8ZRP", - "WXzN2TC+vLi84vPpMOfXnEa0hFKbFU0n4w1YFsk0KcSiKKFM2Gg4TEaLZDRcZHR9d65jG9v6XPuKSGEd", - "0XPSLPLOECVbwIt9YYA5RDQdD8eTeDiOx+Ob0TgdTtPR5DfaOIRdTOfX44vreHIBw3g6GY3j7IqP4tmY", - "X0/47OI6u8zQIZqLueiRNpqlo6vftjlVZ/V4PJzGy1EyniUX8aKq49l4llzNkuEsvsyBT0ezKY3oEowV", - "Wvns2OYRTWmzE0UuBRfsjRFLzHG6EUPX5/s8uPC0y8Ma4grmCDNAUAxzIpNAHoUriCuEJZVkbq5NGQKj", - "HBjF5CcwSzA/YsL8tby2XtB9eOxP6ibhnCZOP4AiuWSi/Buy+pUitYKnCnIHnPhlROd5bQzwKNheshXJ", - "gLCdlc4wZQUo1+xhit8qXGnrPAfgRCvCiAFnVgl5Ow+ShFXfO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dHbOoac+k3ULm78H+0va", + "l7v1HS7dS5TBc/vxfj04OpR60yCtmYs1yWxPRsL6UOQ7O5suzH892KoHHNPEeNRuPip8LXafGq3/r9H5", + "JaHc/0TuQ3nGvp7/Qfi3QkG0838gR5jTdsng8P9EvJATSDo2ZGiBFOZXL8BRdzZxDoySc3EUBpcvgtHe", + "Pxf8B0XfgKL1+l8BAAD//4W4T1ajJAAA", } // 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 ba43ddc..316cb5d 100644 --- a/pkg/openapi/server.spec.yaml +++ b/pkg/openapi/server.spec.yaml @@ -77,14 +77,30 @@ components: type: string minLength: 1 maxLength: 63 + regionType: + description: The region's provider type. + type: string + enum: + - openstack + regionSpec: + description: Information about the region. + type: object + required: + - type + properties: + type: + $ref: '#/components/schemas/regionType' regionRead: description: A region. type: object required: - metadata + - spec properties: metadata: $ref: 'https://raw.githubusercontent.com/unikorn-cloud/core/main/pkg/openapi/common.spec.yaml#/components/schemas/resourceReadMetadata' + spec: + $ref: '#/components/schemas/regionSpec' regions: description: A list of regions. type: array diff --git a/pkg/openapi/types.go b/pkg/openapi/types.go index f082c8c..5641c33 100644 --- a/pkg/openapi/types.go +++ b/pkg/openapi/types.go @@ -13,6 +13,11 @@ const ( Oauth2AuthenticationScopes = "oauth2Authentication.Scopes" ) +// Defines values for RegionType. +const ( + Openstack RegionType = "openstack" +) + // Flavor A flavor. type Flavor struct { // Cpus The number of CPUs. @@ -76,8 +81,20 @@ type KubernetesNameParameter = string type RegionRead struct { // Metadata Resource metadata valid for all reads. Metadata externalRef0.ResourceReadMetadata `json:"metadata"` + + // Spec Information about the region. + Spec RegionSpec `json:"spec"` } +// RegionSpec Information about the region. +type RegionSpec struct { + // Type The region's provider type. + Type RegionType `json:"type"` +} + +// RegionType The region's provider type. +type RegionType string + // Regions A list of regions. type Regions = []RegionRead diff --git a/pkg/server/options.go b/pkg/server/options.go index 6cff148..2e745b7 100644 --- a/pkg/server/options.go +++ b/pkg/server/options.go @@ -25,6 +25,8 @@ import ( // Options allows server options to be overridden. type Options struct { + Namespace string + // ListenAddress tells the server what to listen on, you shouldn't // need to change this, its already non-privileged and the default // should be modified to avoid clashes with other services e.g prometheus. @@ -55,6 +57,7 @@ type Options struct { // addFlags allows server options to be modified. func (o *Options) AddFlags(f *pflag.FlagSet) { + f.StringVar(&o.Namespace, "namespace", "", "The namespace the service is running in.") f.StringVar(&o.ListenAddress, "server-listen-address", ":6080", "API listener address.") f.DurationVar(&o.ReadTimeout, "server-read-timeout", time.Second, "How long to wait for the client to send the request body.") f.DurationVar(&o.ReadHeaderTimeout, "server-read-header-timeout", time.Second, "How long to wait for the client to send headers.") diff --git a/pkg/server/server.go b/pkg/server/server.go index c9d62b3..e9fb17d 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -153,7 +153,7 @@ func (s *Server) GetServer(client client.Client) (*http.Server, error) { }, } - handlerInterface, err := handler.New(client, &s.HandlerOptions, &s.AuthorizerOptions) + handlerInterface, err := handler.New(client, s.Options.Namespace, &s.HandlerOptions, &s.AuthorizerOptions) if err != nil { return nil, err }