Skip to content

Commit

Permalink
Improve Server Implicitness
Browse files Browse the repository at this point in the history
Basicaly the client was previously required to do a lot of logic to fill
in the blanks, by pushing this into the server it simplifies all clients
and improves UX.
  • Loading branch information
spjmurray committed Mar 4, 2024
1 parent e53d465 commit 375f764
Show file tree
Hide file tree
Showing 14 changed files with 648 additions and 599 deletions.
5 changes: 0 additions & 5 deletions charts/unikorn/crds/unikorn-cloud.org_controlplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,6 @@ spec:
pause:
description: Pause, if true, will inhibit reconciliation.
type: boolean
timeout:
default: 10m
description: Timeout defines how long a control plane is allowed to
provision for before a timeout is triggerd and the request aborts.
type: string
required:
- applicationBundle
type: object
Expand Down
8 changes: 3 additions & 5 deletions charts/unikorn/crds/unikorn-cloud.org_kubernetesclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,8 @@ spec:
pause:
description: Pause, if true, will inhibit reconciliation.
type: boolean
timeout:
default: 20m
description: Timeout is the maximum time to attempt to provision a
cluster before aborting.
region:
description: Region to provision the cluster in.
type: string
workloadPools:
description: WorkloadPools defines the workload cluster topology.
Expand Down Expand Up @@ -570,7 +568,7 @@ spec:
- controlPlane
- network
- openstack
- timeout
- region
- workloadPools
type: object
status:
Expand Down
9 changes: 2 additions & 7 deletions pkg/apis/unikorn/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,6 @@ type ControlPlane struct {
type ControlPlaneSpec struct {
// Pause, if true, will inhibit reconciliation.
Pause bool `json:"pause,omitempty"`
// Timeout defines how long a control plane is allowed to provision for before
// a timeout is triggerd and the request aborts.
// +kubebuilder:default="10m"
Timeout *metav1.Duration `json:"timeout,omitempty"`
// ApplicationBundle defines the applications used to create the control plane.
// Change this to a new bundle to start an upgrade.
ApplicationBundle *string `json:"applicationBundle"`
Expand Down Expand Up @@ -520,9 +516,8 @@ type KubernetesCluster struct {
type KubernetesClusterSpec struct {
// Pause, if true, will inhibit reconciliation.
Pause bool `json:"pause,omitempty"`
// Timeout is the maximum time to attempt to provision a cluster before aborting.
// +kubebuilder:default="20m"
Timeout *metav1.Duration `json:"timeout"`
// Region to provision the cluster in.
Region string `json:"region"`
// Openstack defines global Openstack related configuration.
Openstack *KubernetesClusterOpenstackSpec `json:"openstack"`
// Network defines the Kubernetes networking.
Expand Down
11 changes: 0 additions & 11 deletions pkg/apis/unikorn/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 25 additions & 20 deletions pkg/providers/openstack/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ import (
"encoding/pem"
"errors"
"fmt"
"slices"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
"golang.org/x/exp/slices"

"github.com/unikorn-cloud/core/pkg/constants"
"github.com/unikorn-cloud/core/pkg/util"
Expand Down Expand Up @@ -150,6 +150,22 @@ func (c *ImageClient) verifyImage(image *images.Image) bool {
return ecdsa.VerifyASN1(signingKey, hash[:], signature)
}

func (c *ImageClient) imageValid(image *images.Image) bool {
if image.Status != "active" {
return false
}

if !c.validateProperties(image) {
return false
}

if !c.verifyImage(image) {
return false
}

return true
}

// Images returns a list of images.
func (c *ImageClient) Images(ctx context.Context) ([]images.Image, error) {
tracer := otel.GetTracerProvider().Tracer(constants.Application)
Expand All @@ -168,25 +184,14 @@ func (c *ImageClient) Images(ctx context.Context) ([]images.Image, error) {
}

// Filter out images that aren't compatible.
filtered := []images.Image{}

for i := range result {
image := result[i]

if image.Status != "active" {
continue
}
result = slices.DeleteFunc(result, func(image images.Image) bool {
return !c.imageValid(&image)
})

if !c.validateProperties(&image) {
continue
}

if !c.verifyImage(&image) {
continue
}

filtered = append(filtered, image)
}
// Sort by age, the newest should have the fewest CVEs!
slices.SortStableFunc(result, func(a, b images.Image) int {
return a.CreatedAt.Compare(b.CreatedAt)
})

return filtered, nil
return result, nil
}
Loading

0 comments on commit 375f764

Please sign in to comment.