Skip to content

Commit

Permalink
Update Application API (#149)
Browse files Browse the repository at this point in the history
The previous API was too presecribed to be compatible with the
application service, requiring things to be performed that were totally
unnecessary, so we need a couple tweaks.
  • Loading branch information
spjmurray authored Nov 21, 2024
1 parent 1734292 commit 44f19bd
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 41 deletions.
4 changes: 2 additions & 2 deletions charts/kubernetes/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn Kubernetes Service

type: application

version: v0.2.48
appVersion: v0.2.48
version: v0.2.49
appVersion: v0.2.49

icon: https://raw.githubusercontent.com/unikorn-cloud/assets/main/images/logos/dark-on-light/icon.png

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ spec:
version:
description: Version is the version of the application within
the application type.
pattern: ^v?[0-9]+(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$
type: string
required:
- kind
- name
- version
type: object
required:
- name
Expand All @@ -107,6 +109,7 @@ spec:
version:
description: Version is a semantic version of the bundle, must be
unique.
pattern: ^v?[0-9]+(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$
type: string
required:
- version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ spec:
version:
description: Version is the version of the application within
the application type.
pattern: ^v?[0-9]+(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$
type: string
required:
- kind
- name
- version
type: object
required:
- name
Expand All @@ -107,6 +109,7 @@ spec:
version:
description: Version is a semantic version of the bundle, must be
unique.
pattern: ^v?[0-9]+(\.[0-9]+)?(\.[0-9]+)?(-([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?$
type: string
required:
- version
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/oapi-codegen/runtime v1.1.1
github.com/prometheus/client_golang v1.20.5
github.com/spf13/pflag v1.0.5
github.com/unikorn-cloud/core v0.1.79
github.com/unikorn-cloud/core v0.1.81
github.com/unikorn-cloud/identity v0.2.44
github.com/unikorn-cloud/region v0.1.45
go.opentelemetry.io/otel v1.31.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/unikorn-cloud/core v0.1.79 h1:fdIUG7R2Sa2wBY+x+JLhCzQYuGFQqCf7PS/lB7u1Dzg=
github.com/unikorn-cloud/core v0.1.79/go.mod h1:wEKzCwAnIyTbo27l++Wl+gK95TAxMsFS3y3jbFB03aw=
github.com/unikorn-cloud/core v0.1.81-0.20241121142951-a37272e9e9c6 h1:QuwicUQGV8e914HHKRI2FXGHw+DHFZqr8BCxJsY/ZxQ=
github.com/unikorn-cloud/core v0.1.81-0.20241121142951-a37272e9e9c6/go.mod h1:wEKzCwAnIyTbo27l++Wl+gK95TAxMsFS3y3jbFB03aw=
github.com/unikorn-cloud/core v0.1.81 h1:7x0yyspkuDtjTTXl3+P8uORcVffeUZhvNzdoEDktSjQ=
github.com/unikorn-cloud/core v0.1.81/go.mod h1:wEKzCwAnIyTbo27l++Wl+gK95TAxMsFS3y3jbFB03aw=
github.com/unikorn-cloud/identity v0.2.44 h1:tXV/qsJ77Dkx8ba8gnBFXHWUgBNsJ2oo/5TjnyhkH7U=
github.com/unikorn-cloud/identity v0.2.44/go.mod h1:JMbS6iTYzt0OVt5AkqZys3WVnpLabGvUl8kGWcxzFZI=
github.com/unikorn-cloud/region v0.1.45 h1:qpUwB+s/SEZNHZqwHTYovtWUVdJB2AKEl06NbiIwnOw=
Expand Down
8 changes: 2 additions & 6 deletions pkg/apis/unikorn/v1alpha1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,11 @@ func CompareKubernetesCluster(a, b KubernetesCluster) int {
}

func CompareClusterManagerApplicationBundle(a, b ClusterManagerApplicationBundle) int {
// TODO: while this works now, it won't unless we parse and compare as
// a semantic version.
return strings.Compare(*a.Spec.Version, *b.Spec.Version)
return a.Spec.Version.Compare(&b.Spec.Version)
}

func CompareKubernetesClusterApplicationBundle(a, b KubernetesClusterApplicationBundle) int {
// TODO: while this works now, it won't unless we parse and compare as
// a semantic version.
return strings.Compare(*a.Spec.Version, *b.Spec.Version)
return a.Spec.Version.Compare(&b.Spec.Version)
}

// Get retrieves the named bundle.
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/unikorn/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ type KubernetesClusterApplicationBundle struct {
// ApplicationBundleSpec defines the requested resource state.
type ApplicationBundleSpec struct {
// Version is a semantic version of the bundle, must be unique.
Version *string `json:"version"`
Version unikornv1core.SemanticVersion `json:"version"`
// Preview indicates that this bundle is a preview and should not be
// used by default.
Preview *bool `json:"preview,omitempty"`
Expand Down
6 changes: 1 addition & 5 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.

2 changes: 1 addition & 1 deletion pkg/monitor/upgrade/cluster/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Checker) upgradeResource(ctx context.Context, resource *unikornv1.Kuber
return nil
}

logger.Info("bundle upgrading", "from", *bundle.Spec.Version, "to", *target.Spec.Version)
logger.Info("bundle upgrading", "from", bundle.Spec.Version, "to", target.Spec.Version)

resource.Spec.ApplicationBundle = &target.Name

Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/upgrade/clustermanager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (c *Checker) upgradeResource(ctx context.Context, resource *unikornv1.Clust
return nil
}

logger.Info("bundle upgrading", "from", *bundle.Spec.Version, "to", *target.Spec.Version)
logger.Info("bundle upgrading", "from", bundle.Spec.Version, "to", target.Spec.Version)

resource.Spec.ApplicationBundle = &target.Name

Expand Down
44 changes: 30 additions & 14 deletions pkg/provisioners/managers/cluster/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ func newApplicationReferenceGetter(cluster *unikornv1.KubernetesCluster) *Applic
}
}

func (a *ApplicationReferenceGetter) getApplication(ctx context.Context, name string) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) getApplication(ctx context.Context, name string) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
namespace, err := coreclient.NamespaceFromContext(ctx)
if err != nil {
return nil, err
return nil, nil, err
}

// TODO: we could cache this, it's from a cache anyway, so quite cheap...
cli, err := coreclient.ProvisionerClientFromContext(ctx)
if err != nil {
return nil, err
return nil, nil, err
}

key := client.ObjectKey{
Expand All @@ -98,45 +98,61 @@ func (a *ApplicationReferenceGetter) getApplication(ctx context.Context, name st
bundle := &unikornv1.KubernetesClusterApplicationBundle{}

if err := cli.Get(ctx, key, bundle); err != nil {
return nil, err
return nil, nil, err
}

reference, err := bundle.Spec.GetApplication(name)
if err != nil {
return nil, nil, err
}

key = client.ObjectKey{
Namespace: namespace,
Name: *reference.Name,
}

application := &unikornv1core.HelmApplication{}

if err := cli.Get(ctx, key, application); err != nil {
return nil, nil, err
}

return bundle.Spec.GetApplication(name)
return application, &reference.Version, nil
}

func (a *ApplicationReferenceGetter) clusterOpenstack(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) clusterOpenstack(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "cluster-openstack")
}

func (a *ApplicationReferenceGetter) cilium(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) cilium(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "cilium")
}

func (a *ApplicationReferenceGetter) openstackCloudProvider(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) openstackCloudProvider(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "openstack-cloud-provider")
}

func (a *ApplicationReferenceGetter) openstackPluginCinderCSI(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) openstackPluginCinderCSI(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "openstack-plugin-cinder-csi")
}

func (a *ApplicationReferenceGetter) metricsServer(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) metricsServer(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "metrics-server")
}

func (a *ApplicationReferenceGetter) nvidiaGPUOperator(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) nvidiaGPUOperator(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "nvidia-gpu-operator")
}

func (a *ApplicationReferenceGetter) amdGPUOperator(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) amdGPUOperator(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "amd-gpu-operator")
}

func (a *ApplicationReferenceGetter) clusterAutoscaler(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) clusterAutoscaler(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "cluster-autoscaler")
}

func (a *ApplicationReferenceGetter) clusterAutoscalerOpenstack(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) clusterAutoscalerOpenstack(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "cluster-autoscaler-openstack")
}

Expand Down
32 changes: 24 additions & 8 deletions pkg/provisioners/managers/clustermanager/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func newApplicationReferenceGetter(clusterManager *unikornv1.ClusterManager) *Ap
}
}

func (a *ApplicationReferenceGetter) getApplication(ctx context.Context, name string) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) getApplication(ctx context.Context, name string) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
namespace, err := coreclient.NamespaceFromContext(ctx)
if err != nil {
return nil, err
return nil, nil, err
}

cli, err := coreclient.ProvisionerClientFromContext(ctx)
if err != nil {
return nil, err
return nil, nil, err
}

key := client.ObjectKey{
Expand All @@ -86,21 +86,37 @@ func (a *ApplicationReferenceGetter) getApplication(ctx context.Context, name st
bundle := &unikornv1.ClusterManagerApplicationBundle{}

if err := cli.Get(ctx, key, bundle); err != nil {
return nil, err
return nil, nil, err
}

return bundle.Spec.GetApplication(name)
reference, err := bundle.Spec.GetApplication(name)
if err != nil {
return nil, nil, err
}

key = client.ObjectKey{
Namespace: namespace,
Name: *reference.Name,
}

application := &unikornv1core.HelmApplication{}

if err := cli.Get(ctx, key, application); err != nil {
return nil, nil, err
}

return application, &reference.Version, nil
}

func (a *ApplicationReferenceGetter) vCluster(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) vCluster(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "vcluster")
}

func (a *ApplicationReferenceGetter) certManager(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) certManager(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "cert-manager")
}

func (a *ApplicationReferenceGetter) clusterAPI(ctx context.Context) (*unikornv1core.ApplicationReference, error) {
func (a *ApplicationReferenceGetter) clusterAPI(ctx context.Context) (*unikornv1core.HelmApplication, *unikornv1core.SemanticVersion, error) {
return a.getApplication(ctx, "cluster-api")
}

Expand Down

0 comments on commit 44f19bd

Please sign in to comment.