Skip to content

Commit ab12ebf

Browse files
kvapsclaude
andcommitted
feat: ResourceDefinition CRD + /v1/resource-definitions CRUD
Phase 2 third slice. ResourceDefinition is the named entity per PVC; one RD becomes one or more Resources (replicas) at autoplace time. - pkg/api/v1: ResourceDefinition wire shape + ResourceDefinitionCreate wrapper (POST body shape upstream uses). - api/v1alpha1: CRD with externalName, resourceGroupName, props, flags, volumeDefinitions. - pkg/store: ResourceDefinitionStore interface + InMemory + k8s impl; shared 6-case suite (list-empty, create→get, dup→409, get-missing→404, delete-missing→404, delete-removes) green on both stores. - pkg/rest/resource_definitions.go: 5 handlers; create unwraps the upstream {resource_definition: {...}} envelope. - 5 contract tests against golinstor (list, create round-trip via ResourceDefinitionCreate, conflict→409, get-missing→404, delete cascades, 503-without-store). CSI MVP api-surface.md: 5/12 RD endpoints ✅. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent e965c6f commit ab12ebf

29 files changed

Lines changed: 1409 additions & 12 deletions

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ linters:
7575
- in
7676
- sp
7777
- st
78+
- s
7879
- rd
7980
- vd
8081
- rg
@@ -124,6 +125,10 @@ linters:
124125
- linters:
125126
- dupl
126127
path: pkg/store/k8s/
128+
# Same applies to the in-memory store implementations.
129+
- linters:
130+
- dupl
131+
path: pkg/store/inmemory_
127132
# REST handlers follow the same Get/Create/Update/Delete shape per
128133
# resource for the same reason.
129134
- linters:

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,12 @@ resources:
3333
kind: ResourceGroup
3434
path: github.com/cozystack/blockstor/api/v1alpha1
3535
version: v1alpha1
36+
- api:
37+
crdVersion: v1
38+
controller: true
39+
domain: blockstor.io
40+
group: blockstor.io
41+
kind: ResourceDefinition
42+
path: github.com/cozystack/blockstor/api/v1alpha1
43+
version: v1alpha1
3644
version: "3"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Copyright 2026 Cozystack contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// ResourceDefinitionSpec is the desired state of a LINSTOR
24+
// ResourceDefinition — the named entity from which Resource (replica)
25+
// instances are spawned. linstor-csi creates one per PVC.
26+
type ResourceDefinitionSpec struct {
27+
// externalName is the user-facing name surfaced by csi (CSI volume id).
28+
// Empty means the same as metadata.name.
29+
// +optional
30+
ExternalName string `json:"externalName,omitempty"`
31+
32+
// resourceGroupName references the ResourceGroup template this RD was
33+
// spawned from (or empty if directly created).
34+
// +optional
35+
ResourceGroupName string `json:"resourceGroupName,omitempty"`
36+
37+
// props is the LINSTOR property map.
38+
// +optional
39+
Props map[string]string `json:"props,omitempty"`
40+
41+
// flags carries user-controlled RD flags (DELETE, INACTIVE, ...).
42+
// +optional
43+
Flags []string `json:"flags,omitempty"`
44+
45+
// volumeDefinitions are the volume slots inside this RD.
46+
// +optional
47+
VolumeDefinitions []ResourceDefinitionVolume `json:"volumeDefinitions,omitempty"`
48+
}
49+
50+
// ResourceDefinitionVolume is one volume slot inside an RD.
51+
type ResourceDefinitionVolume struct {
52+
VolumeNumber int32 `json:"volumeNumber"`
53+
SizeKib int64 `json:"sizeKib"`
54+
// +optional
55+
Props map[string]string `json:"props,omitempty"`
56+
// +optional
57+
Flags []string `json:"flags,omitempty"`
58+
}
59+
60+
// ResourceDefinitionStatus is the observed state.
61+
type ResourceDefinitionStatus struct {
62+
// conditions represent the current state of the ResourceDefinition.
63+
// +listType=map
64+
// +listMapKey=type
65+
// +optional
66+
Conditions []metav1.Condition `json:"conditions,omitempty"`
67+
}
68+
69+
// +kubebuilder:object:root=true
70+
// +kubebuilder:subresource:status
71+
// +kubebuilder:resource:scope=Cluster
72+
73+
// ResourceDefinition is the Schema for the resourcedefinitions API
74+
type ResourceDefinition struct {
75+
metav1.TypeMeta `json:",inline"`
76+
77+
// metadata is a standard object metadata
78+
// +optional
79+
metav1.ObjectMeta `json:"metadata,omitzero"`
80+
81+
// spec defines the desired state of ResourceDefinition
82+
// +required
83+
Spec ResourceDefinitionSpec `json:"spec"`
84+
85+
// status defines the observed state of ResourceDefinition
86+
// +optional
87+
Status ResourceDefinitionStatus `json:"status,omitzero"`
88+
}
89+
90+
// +kubebuilder:object:root=true
91+
92+
// ResourceDefinitionList contains a list of ResourceDefinition
93+
type ResourceDefinitionList struct {
94+
metav1.TypeMeta `json:",inline"`
95+
metav1.ListMeta `json:"metadata,omitzero"`
96+
Items []ResourceDefinition `json:"items"`
97+
}
98+
99+
func init() {
100+
SchemeBuilder.Register(&ResourceDefinition{}, &ResourceDefinitionList{})
101+
}

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ func main() {
207207
setupLog.Error(err, "Failed to create controller", "controller", "resourcegroup")
208208
os.Exit(1)
209209
}
210+
if err := (&controller.ResourceDefinitionReconciler{
211+
Client: mgr.GetClient(),
212+
Scheme: mgr.GetScheme(),
213+
}).SetupWithManager(mgr); err != nil {
214+
setupLog.Error(err, "Failed to create controller", "controller", "resourcedefinition")
215+
os.Exit(1)
216+
}
210217
// +kubebuilder:scaffold:builder
211218

212219
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

0 commit comments

Comments
 (0)