Skip to content

Commit b84efb5

Browse files
authored
Remove API Pointers (#230)
There are quite a lot of places where we use pointers but the value is required. We should remove these so that the code that relies on these types doesn't have to dereference, and I don't get asked questions about nil pointer checks. Fixes #222
1 parent 2e711b9 commit b84efb5

File tree

21 files changed

+116
-221
lines changed

21 files changed

+116
-221
lines changed

charts/kubernetes/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ description: A Helm chart for deploying Unikorn Kubernetes Service
44

55
type: application
66

7-
version: v0.2.64-rc1
8-
appVersion: v0.2.64-rc1
7+
version: v0.2.64-rc2
8+
appVersion: v0.2.64-rc2
99

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

charts/kubernetes/crds/unikorn-cloud.org_kubernetesclusters.yaml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ spec:
288288
description: Image is the region service image to deploy with.
289289
type: string
290290
replicas:
291-
default: 3
292291
description: Replicas is the initial pool size to deploy.
293292
minimum: 0
294293
type: integer
@@ -389,25 +388,15 @@ spec:
389388
Autoscaling contains optional sclaing limits and scheduling
390389
hints for autoscaling.
391390
properties:
392-
maximumReplicas:
393-
description: |-
394-
MaximumReplicas defines the maximum numer of replicas that
395-
this pool can be scaled up to.
396-
minimum: 1
397-
type: integer
398391
minimumReplicas:
399392
description: |-
400393
MinimumReplicas defines the minimum number of replicas that
401394
this pool can be scaled down to.
402395
minimum: 0
403396
type: integer
404397
required:
405-
- maximumReplicas
406398
- minimumReplicas
407399
type: object
408-
x-kubernetes-validations:
409-
- message: maximumReplicas must be greater than minimumReplicas
410-
rule: (self.maximumReplicas > self.minimumReplicas)
411400
diskSize:
412401
anyOf:
413402
- type: integer
@@ -458,7 +447,6 @@ spec:
458447
description: Name is the name of the pool.
459448
type: string
460449
replicas:
461-
default: 3
462450
description: Replicas is the initial pool size to deploy.
463451
minimum: 0
464452
type: integer

charts/kubernetes/crds/unikorn-cloud.org_virtualkubernetesclusters.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ spec:
276276
description: Name is the name of the pool.
277277
type: string
278278
replicas:
279-
default: 3
280279
description: Replicas is the initial pool size to deploy.
281280
minimum: 0
282281
type: integer

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ require (
1313
github.com/prometheus/client_golang v1.22.0
1414
github.com/spf13/pflag v1.0.6
1515
github.com/stretchr/testify v1.10.0
16-
github.com/unikorn-cloud/core v0.1.95-rc1
16+
github.com/unikorn-cloud/core v0.1.95-rc2
1717
github.com/unikorn-cloud/identity v0.2.63-rc1
1818
github.com/unikorn-cloud/region v0.1.54-rc1
1919
go.opentelemetry.io/otel v1.35.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
173173
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
174174
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
175175
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
176-
github.com/unikorn-cloud/core v0.1.95-rc1 h1:guNDD9MOsHwEbyEAyqtGOc0umyQ586OYHcvh7jHXeyg=
177-
github.com/unikorn-cloud/core v0.1.95-rc1/go.mod h1:OdZlqXlkO0EFaThARFYRctKAtsVKimhSZid72OaC43Y=
176+
github.com/unikorn-cloud/core v0.1.95-rc2 h1:l1zNxPTFqrRIuKPXzvsCDsc/5B6hquF7GPjHJGviIUA=
177+
github.com/unikorn-cloud/core v0.1.95-rc2/go.mod h1:OdZlqXlkO0EFaThARFYRctKAtsVKimhSZid72OaC43Y=
178178
github.com/unikorn-cloud/identity v0.2.63-rc1 h1:RsZ+pxOQ8s77usWfsZtBKdHDyQZc+gcQAuEyGZX37NY=
179179
github.com/unikorn-cloud/identity v0.2.63-rc1/go.mod h1:ba6iPmqnjOpTT4D7Hxix0IHtPZamktFIgziQ1SckMUI=
180180
github.com/unikorn-cloud/region v0.1.54-rc1 h1:LE9vmhTpASmmtFtFKE72JhL0s5sSSU7b+L3VkFZvA+Y=

pkg/apis/unikorn/v1alpha1/helpers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ func (c *KubernetesCluster) UpgradeSpec() *ApplicationBundleAutoUpgradeSpec {
144144

145145
// AutoscalingEnabled indicates whether cluster autoscaling is enabled for the cluster.
146146
func (c *KubernetesCluster) AutoscalingEnabled() bool {
147-
return c.Spec.Features != nil && c.Spec.Features.Autoscaling != nil && *c.Spec.Features.Autoscaling
147+
return c.Spec.Features != nil && c.Spec.Features.Autoscaling
148148
}
149149

150150
// GPUOperatorEnabled indicates whether to install the GPU operator.
151151
func (c *KubernetesCluster) GPUOperatorEnabled() bool {
152-
return c.Spec.Features != nil && c.Spec.Features.GPUOperator != nil && *c.Spec.Features.GPUOperator
152+
return c.Spec.Features != nil && c.Spec.Features.GPUOperator
153153
}
154154

155155
func (c *KubernetesCluster) GetWorkloadPool(name string) *KubernetesClusterWorkloadPoolsPoolSpec {
@@ -249,7 +249,7 @@ func (l *ClusterManagerApplicationBundleList) Upgradable() *ClusterManagerApplic
249249
result := &ClusterManagerApplicationBundleList{}
250250

251251
for _, bundle := range l.Items {
252-
if bundle.Spec.Preview != nil && *bundle.Spec.Preview {
252+
if bundle.Spec.Preview {
253253
continue
254254
}
255255

@@ -267,7 +267,7 @@ func (l *KubernetesClusterApplicationBundleList) Upgradable() *KubernetesCluster
267267
result := &KubernetesClusterApplicationBundleList{}
268268

269269
for _, bundle := range l.Items {
270-
if bundle.Spec.Preview != nil && *bundle.Spec.Preview {
270+
if bundle.Spec.Preview {
271271
continue
272272
}
273273

@@ -283,8 +283,8 @@ func (l *KubernetesClusterApplicationBundleList) Upgradable() *KubernetesCluster
283283

284284
func (s *ApplicationBundleSpec) GetApplication(name string) (*unikornv1core.ApplicationReference, error) {
285285
for i := range s.Applications {
286-
if *s.Applications[i].Name == name {
287-
return s.Applications[i].Reference, nil
286+
if s.Applications[i].Name == name {
287+
return &s.Applications[i].Reference, nil
288288
}
289289
}
290290

pkg/apis/unikorn/v1alpha1/types.go

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type ClusterManagerSpec struct {
5757
Tags unikornv1core.TagList `json:"tags,omitempty"`
5858
// ApplicationBundle defines the applications used to create the cluster manager.
5959
// Change this to a new bundle to start an upgrade.
60-
ApplicationBundle *string `json:"applicationBundle"`
60+
ApplicationBundle string `json:"applicationBundle"`
6161
// ApplicationBundleAutoUpgrade enables automatic upgrade of application bundles.
6262
// When no properties are set in the specification, the platform will automatically
6363
// choose an upgrade time for your resource. This will be before a working day
@@ -75,22 +75,18 @@ type ClusterManagerStatus struct {
7575
// File is a file that can be deployed to a cluster node on creation.
7676
type File struct {
7777
// Path is the absolute path to create the file in.
78-
Path *string `json:"path"`
78+
Path string `json:"path"`
7979
// Content is the file contents.
8080
Content []byte `json:"content"`
8181
}
8282

8383
// MachineGenericAutoscaling defines generic autoscaling configuration.
84-
// +kubebuilder:validation:XValidation:message="maximumReplicas must be greater than minimumReplicas",rule=(self.maximumReplicas > self.minimumReplicas)
84+
// The maximum number of replicas are sourced from the pool's replica count.
8585
type MachineGenericAutoscaling struct {
8686
// MinimumReplicas defines the minimum number of replicas that
8787
// this pool can be scaled down to.
8888
// +kubebuilder:validation:Minimum=0
89-
MinimumReplicas *int `json:"minimumReplicas"`
90-
// MaximumReplicas defines the maximum numer of replicas that
91-
// this pool can be scaled up to.
92-
// +kubebuilder:validation:Minimum=1
93-
MaximumReplicas *int `json:"maximumReplicas"`
89+
MinimumReplicas int `json:"minimumReplicas"`
9490
}
9591

9692
// KubernetesWorkloadPoolSpec defines the requested machine pool
@@ -151,20 +147,20 @@ type KubernetesClusterSpec struct {
151147
// Version is the Kubernetes version to install. For performance
152148
// reasons this should match what is already pre-installed on the
153149
// provided image.
154-
Version *unikornv1core.SemanticVersion `json:"version"`
150+
Version unikornv1core.SemanticVersion `json:"version"`
155151
// Network defines the Kubernetes networking.
156-
Network *KubernetesClusterNetworkSpec `json:"network"`
152+
Network KubernetesClusterNetworkSpec `json:"network"`
157153
// API defines Kubernetes API specific options.
158154
API *KubernetesClusterAPISpec `json:"api,omitempty"`
159155
// ControlPlane defines the cluster manager topology.
160-
ControlPlane *unikornv1core.MachineGeneric `json:"controlPlane"`
156+
ControlPlane unikornv1core.MachineGeneric `json:"controlPlane"`
161157
// WorkloadPools defines the workload cluster topology.
162-
WorkloadPools *KubernetesClusterWorkloadPoolsSpec `json:"workloadPools"`
158+
WorkloadPools KubernetesClusterWorkloadPoolsSpec `json:"workloadPools"`
163159
// Features defines add-on features that can be enabled for the cluster.
164160
Features *KubernetesClusterFeaturesSpec `json:"features,omitempty"`
165161
// ApplicationBundle defines the applications used to create the cluster.
166162
// Change this to a new bundle to start an upgrade.
167-
ApplicationBundle *string `json:"applicationBundle"`
163+
ApplicationBundle string `json:"applicationBundle"`
168164
// ApplicationBundleAutoUpgrade enables automatic upgrade of application bundles.
169165
// When no properties are set in the specification, the platform will automatically
170166
// choose an upgrade time for your resource. This will be before a working day
@@ -185,19 +181,19 @@ type KubernetesClusterAPISpec struct {
185181
type KubernetesClusterNetworkSpec struct {
186182
unikornv1core.NetworkGeneric `json:",inline"`
187183
// PodNetwork is the IPv4 prefix for the pod network.
188-
PodNetwork *unikornv1core.IPv4Prefix `json:"podNetwork"`
184+
PodNetwork unikornv1core.IPv4Prefix `json:"podNetwork"`
189185
// ServiceNetwork is the IPv4 prefix for the service network.
190-
ServiceNetwork *unikornv1core.IPv4Prefix `json:"serviceNetwork"`
186+
ServiceNetwork unikornv1core.IPv4Prefix `json:"serviceNetwork"`
191187
}
192188

193189
type KubernetesClusterFeaturesSpec struct {
194190
// Autoscaling enables the provision of a cluster autoscaler.
195191
// This is only installed if a workload pool has autoscaling enabled.
196-
Autoscaling *bool `json:"autoscaling,omitempty"`
192+
Autoscaling bool `json:"autoscaling,omitempty"`
197193
// GPUOperator enables the provision of a GPU operator.
198194
// This is only installed if a workload pool has a flavor that defines
199195
// a valid GPU specification and vendor.
200-
GPUOperator *bool `json:"gpuOperator,omitempty"`
196+
GPUOperator bool `json:"gpuOperator,omitempty"`
201197
}
202198

203199
type KubernetesClusterWorkloadPoolsPoolSpec struct {
@@ -257,7 +253,7 @@ type VirtualKubernetesClusterSpec struct {
257253
WorkloadPools []VirtualKubernetesClusterWorkloadPoolSpec `json:"workloadPools"`
258254
// ApplicationBundle defines the applications used to create the cluster.
259255
// Change this to a new bundle to start an upgrade.
260-
ApplicationBundle *string `json:"applicationBundle"`
256+
ApplicationBundle string `json:"applicationBundle"`
261257
// ApplicationBundleAutoUpgrade enables automatic upgrade of application bundles.
262258
// When no properties are set in the specification, the platform will automatically
263259
// choose an upgrade time for your resource. This will be before a working day
@@ -270,11 +266,10 @@ type VirtualKubernetesClusterWorkloadPoolSpec struct {
270266
// Name is the name of the pool.
271267
Name string `json:"name"`
272268
// Flavor is the regions service flavor to deploy with.
273-
FlavorID *string `json:"flavorId"`
269+
FlavorID string `json:"flavorId"`
274270
// Replicas is the initial pool size to deploy.
275271
// +kubebuilder:validation:Minimum=0
276-
// +kubebuilder:default=3
277-
Replicas *int `json:"replicas,omitempty"`
272+
Replicas int `json:"replicas,omitempty"`
278273
}
279274

280275
// VirtualKubernetesClusterStatus defines the observed state of the Kubernetes cluster.
@@ -365,7 +360,7 @@ type ApplicationBundleSpec struct {
365360
Version unikornv1core.SemanticVersion `json:"version"`
366361
// Preview indicates that this bundle is a preview and should not be
367362
// used by default.
368-
Preview *bool `json:"preview,omitempty"`
363+
Preview bool `json:"preview,omitempty"`
369364
// EndOfLife marks when this bundle should not be advertised any more
370365
// by Unikorn server. It also provides a hint that users should upgrade
371366
// ahead of the deadline, or that a forced upgrade should be triggered.
@@ -377,9 +372,9 @@ type ApplicationBundleSpec struct {
377372
type ApplicationNamedReference struct {
378373
// Name is the name of the application. This must match what is encoded into
379374
// Unikorn's application management engine.
380-
Name *string `json:"name"`
375+
Name string `json:"name"`
381376
// Reference is a reference to the application definition.
382-
Reference *unikornv1core.ApplicationReference `json:"reference"`
377+
Reference unikornv1core.ApplicationReference `json:"reference"`
383378
}
384379

385380
type ApplicationBundleStatus struct{}

0 commit comments

Comments
 (0)