Skip to content

Commit c360a71

Browse files
Progress.....
1 parent b327793 commit c360a71

File tree

10 files changed

+253
-80
lines changed

10 files changed

+253
-80
lines changed

Tiltfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ if not os.getenv('TILT_VALUES_PATH'):
1111
fail("TILT_VALUES_PATH is not set.")
1212
if not os.path.exists(os.getenv('TILT_VALUES_PATH')):
1313
fail("TILT_VALUES_PATH "+ os.getenv('TILT_VALUES_PATH') + " does not exist.")
14+
tilt_values = os.getenv('TILT_VALUES_PATH')
1415

1516
# The upgrade job may take a long time to run, so it is disabled by default.
1617
enable_postgres_upgrade = False
@@ -22,14 +23,21 @@ helm_repo(
2223
labels=['Repositories'],
2324
)
2425

26+
def kubebuilder_binary_files(path):
27+
"""
28+
Return all usual binary files in a kubebuilder operator path.
29+
Can be used to perform selective watching on code paths for docker builds.
30+
"""
31+
return [path + '/cmd', path + '/api', path + '/internal', path + '/go.mod', path + '/go.sum']
32+
2533
########### Reservations Operator & CRDs
2634
docker_build('ghcr.io/cobaltcore-dev/cortex-reservations-operator', '.',
2735
dockerfile='Dockerfile.kubebuilder',
2836
build_args={'GO_MOD_PATH': 'reservations'},
29-
only=['reservations/', 'lib/', 'api/'],
37+
only=kubebuilder_binary_files('reservations') + ['api/', 'lib/'],
3038
)
3139
local('sh helm/sync.sh reservations/dist/chart')
32-
k8s_yaml(helm('reservations/dist/chart', name='cortex-reservations'))
40+
k8s_yaml(helm('reservations/dist/chart', name='cortex-reservations', values=[tilt_values]))
3341

3442
########### Dev Dependencies
3543
local('sh helm/sync.sh helm/dev/cortex-prometheus-operator')
@@ -67,7 +75,6 @@ k8s_resource('cortex-plutono', port_forwards=[
6775
], labels=['Monitoring'])
6876

6977
########### Cortex Bundles
70-
tilt_values = os.getenv('TILT_VALUES_PATH')
7178
docker_build('ghcr.io/cobaltcore-dev/cortex', '.', only=[
7279
'internal/', 'commands/', 'main.go', 'go.mod', 'go.sum', 'Makefile',
7380
'lib/', 'api/', 'reservations/api/',

reservations/api/v1alpha1/computereservation_types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ type ComputeReservationSpecKind string
1414
const (
1515
// Reservation for a specific virtual machine configuration.
1616
ComputeReservationSpecKindInstance ComputeReservationSpecKind = "instance"
17+
// Reservation for a bare resource.
18+
ComputeReservationSpecKindBareResource ComputeReservationSpecKind = "bare"
1719
)
1820

1921
// Specification for an instance reservation.
@@ -30,6 +32,16 @@ type ComputeReservationSpecInstance struct {
3032
ExtraSpecs map[string]string `json:"extraSpecs,omitempty"`
3133
}
3234

35+
// Specification for a bare resource reservation
36+
type ComputeReservationSpecBareResource struct {
37+
// The amount of CPU to reserve (e.g., "2", "500m").
38+
CPU resource.Quantity `json:"cpu"`
39+
// The amount of memory to reserve (e.g., "1Gi", "512Mi").
40+
Memory resource.Quantity `json:"memory"`
41+
// The amount of disk space to reserve (e.g., "10Gi", "500Mi").
42+
Disk resource.Quantity `json:"disk"`
43+
}
44+
3345
// ComputeReservationSpec defines the desired state of ComputeReservation.
3446
type ComputeReservationSpec struct {
3547
Kind ComputeReservationSpecKind `json:"kind"`
@@ -42,6 +54,9 @@ type ComputeReservationSpec struct {
4254
// If reservation kind is instance, this field will contain metadata
4355
// necessary to determine if the instance reservation can be fulfilled.
4456
Instance ComputeReservationSpecInstance `json:"instance,omitempty"`
57+
// If reservation kind is bare resource, this field will contain metadata
58+
// necessary to determine if the bare resource reservation can be fulfilled.
59+
BareResource ComputeReservationSpecBareResource `json:"bareResource,omitempty"`
4560
}
4661

4762
// The phase in which the reservation is.
@@ -66,6 +81,10 @@ type ComputeReservationStatus struct {
6681

6782
// +kubebuilder:object:root=true
6883
// +kubebuilder:subresource:status
84+
// +kubebuilder:resource:scope=Cluster,shortName=cres
85+
// +kubebuilder:printcolumn:name="Host",type="string",JSONPath=".status.host"
86+
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
87+
// +kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.error"
6988

7089
// ComputeReservation is the Schema for the computereservations API
7190
type ComputeReservation struct {

reservations/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

reservations/config/crd/bases/reservations.cortex_computereservations.yaml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@ spec:
1111
kind: ComputeReservation
1212
listKind: ComputeReservationList
1313
plural: computereservations
14+
shortNames:
15+
- cres
1416
singular: computereservation
15-
scope: Namespaced
17+
scope: Cluster
1618
versions:
17-
- name: v1alpha1
19+
- additionalPrinterColumns:
20+
- jsonPath: .status.host
21+
name: Host
22+
type: string
23+
- jsonPath: .status.phase
24+
name: Phase
25+
type: string
26+
- jsonPath: .status.error
27+
name: Error
28+
type: string
29+
name: v1alpha1
1830
schema:
1931
openAPIV3Schema:
2032
description: ComputeReservation is the Schema for the computereservations
@@ -40,6 +52,38 @@ spec:
4052
spec:
4153
description: spec defines the desired state of ComputeReservation
4254
properties:
55+
bareResource:
56+
description: |-
57+
If reservation kind is bare resource, this field will contain metadata
58+
necessary to determine if the bare resource reservation can be fulfilled.
59+
properties:
60+
cpu:
61+
anyOf:
62+
- type: integer
63+
- type: string
64+
description: The amount of CPU to reserve (e.g., "2", "500m").
65+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
66+
x-kubernetes-int-or-string: true
67+
disk:
68+
anyOf:
69+
- type: integer
70+
- type: string
71+
description: The amount of disk space to reserve (e.g., "10Gi",
72+
"500Mi").
73+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
74+
x-kubernetes-int-or-string: true
75+
memory:
76+
anyOf:
77+
- type: integer
78+
- type: string
79+
description: The amount of memory to reserve (e.g., "1Gi", "512Mi").
80+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
81+
x-kubernetes-int-or-string: true
82+
required:
83+
- cpu
84+
- disk
85+
- memory
86+
type: object
4387
domainID:
4488
description: The domain ID to reserve for.
4589
type: string

reservations/dist/chart/templates/crd/reservations.cortex_computereservations.yaml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ spec:
1717
kind: ComputeReservation
1818
listKind: ComputeReservationList
1919
plural: computereservations
20+
shortNames:
21+
- cres
2022
singular: computereservation
21-
scope: Namespaced
23+
scope: Cluster
2224
versions:
23-
- name: v1alpha1
25+
- additionalPrinterColumns:
26+
- jsonPath: .status.host
27+
name: Host
28+
type: string
29+
- jsonPath: .status.phase
30+
name: Phase
31+
type: string
32+
- jsonPath: .status.error
33+
name: Error
34+
type: string
35+
name: v1alpha1
2436
schema:
2537
openAPIV3Schema:
2638
description: ComputeReservation is the Schema for the computereservations
@@ -46,6 +58,38 @@ spec:
4658
spec:
4759
description: spec defines the desired state of ComputeReservation
4860
properties:
61+
bareResource:
62+
description: |-
63+
If reservation kind is bare resource, this field will contain metadata
64+
necessary to determine if the bare resource reservation can be fulfilled.
65+
properties:
66+
cpu:
67+
anyOf:
68+
- type: integer
69+
- type: string
70+
description: The amount of CPU to reserve (e.g., "2", "500m").
71+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
72+
x-kubernetes-int-or-string: true
73+
disk:
74+
anyOf:
75+
- type: integer
76+
- type: string
77+
description: The amount of disk space to reserve (e.g., "10Gi",
78+
"500Mi").
79+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
80+
x-kubernetes-int-or-string: true
81+
memory:
82+
anyOf:
83+
- type: integer
84+
- type: string
85+
description: The amount of memory to reserve (e.g., "1Gi", "512Mi").
86+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
87+
x-kubernetes-int-or-string: true
88+
required:
89+
- cpu
90+
- disk
91+
- memory
92+
type: object
4993
domainID:
5094
description: The domain ID to reserve for.
5195
type: string

reservations/dist/chart/templates/manager/manager.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ spec:
5252
{{- toYaml .Values.controllerManager.container.resources | nindent 12 }}
5353
securityContext:
5454
{{- toYaml .Values.controllerManager.container.securityContext | nindent 12 }}
55-
{{- if and .Values.certmanager.enable .Values.metrics.enable }}
5655
volumeMounts:
5756
- name: reservations-controller-manager-config-volume
5857
mountPath: /etc/config
@@ -64,12 +63,10 @@ spec:
6463
mountPath: /tmp/k8s-metrics-server/metrics-certs
6564
readOnly: true
6665
{{- end }}
67-
{{- end }}
6866
securityContext:
6967
{{- toYaml .Values.controllerManager.securityContext | nindent 8 }}
7068
serviceAccountName: {{ .Values.controllerManager.serviceAccountName }}
7169
terminationGracePeriodSeconds: {{ .Values.controllerManager.terminationGracePeriodSeconds }}
72-
{{- if and .Values.certmanager.enable .Values.metrics.enable }}
7370
volumes:
7471
# Custom values to configure the controller-manager.
7572
- name: reservations-controller-manager-config-volume
@@ -83,7 +80,6 @@ spec:
8380
secret:
8481
secretName: metrics-server-cert
8582
{{- end }}
86-
{{- end }}
8783
---
8884
apiVersion: v1
8985
kind: ConfigMap

reservations/dist/chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ controllerManager:
2424
resources:
2525
limits:
2626
cpu: 500m
27-
memory: 128Mi
27+
memory: 512Mi
2828
requests:
2929
cpu: 10m
3030
memory: 64Mi

reservations/internal/controller/controller.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (r *ComputeReservationReconciler) Reconcile(ctx context.Context, req ctrl.R
5656
switch res.Spec.Kind {
5757
case v1alpha1.ComputeReservationSpecKindInstance:
5858
return r.reconcileInstanceReservation(ctx, req, res)
59+
case v1alpha1.ComputeReservationSpecKindBareResource:
60+
return r.reconcileBareResourceReservation(ctx, req, res)
5961
default:
6062
log.Info("reservation kind is not supported, skipping", "reservation", req.Name, "kind", res.Spec.Kind)
6163
return ctrl.Result{}, nil // Don't need to requeue.
@@ -83,7 +85,7 @@ func (r *ComputeReservationReconciler) reconcileInstanceReservation(
8385
log.Error(err, "failed to update reservation status")
8486
return ctrl.Result{RequeueAfter: jobloop.DefaultJitter(time.Minute)}, err
8587
}
86-
return ctrl.Result{}, errors.New("hypervisor type is not supported")
88+
return ctrl.Result{}, nil // No need to requeue, the reservation is now failed.
8789
}
8890

8991
// Convert resource.Quantity to integers for the API
@@ -159,6 +161,24 @@ func (r *ComputeReservationReconciler) reconcileInstanceReservation(
159161
return ctrl.Result{}, nil // No need to requeue, the reservation is now active.
160162
}
161163

164+
// Reconcile a bare resource reservation.
165+
func (r *ComputeReservationReconciler) reconcileBareResourceReservation(
166+
ctx context.Context,
167+
req ctrl.Request,
168+
res v1alpha1.ComputeReservation,
169+
) (ctrl.Result, error) {
170+
171+
log := logf.FromContext(ctx)
172+
log.Info("bare resource reservations are not supported", "reservation", req.Name)
173+
res.Status.Phase = v1alpha1.ComputeReservationStatusPhaseFailed
174+
res.Status.Error = "bare resource reservations are not supported"
175+
if err := r.Client.Status().Update(ctx, &res); err != nil {
176+
log.Error(err, "failed to update reservation status")
177+
return ctrl.Result{RequeueAfter: jobloop.DefaultJitter(time.Minute)}, err
178+
}
179+
return ctrl.Result{}, nil
180+
}
181+
162182
// SetupWithManager sets up the controller with the Manager.
163183
func (r *ComputeReservationReconciler) SetupWithManager(mgr ctrl.Manager) error {
164184
return ctrl.NewControllerManagedBy(mgr).

0 commit comments

Comments
 (0)