Skip to content

Commit afba37e

Browse files
authored
Merge pull request #188 from tirthct/hyperfleet-1085
HYPERFLEET-1085 - feat: Add resource service
2 parents 04d5ee4 + dddcad1 commit afba37e

9 files changed

Lines changed: 1052 additions & 74 deletions

File tree

cmd/hyperfleet-api/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/clusters"
2121
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/generic"
2222
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/nodePools"
23+
_ "github.com/openshift-hyperfleet/hyperfleet-api/plugins/resources"
2324
)
2425

2526
// nolint

pkg/api/resource.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,17 @@ type Resource struct {
3131
Generation int32 `json:"generation" gorm:"default:1;not null"`
3232
}
3333

34-
type (
35-
ResourceList []*Resource
36-
ResourceIndex map[string]*Resource
37-
)
38-
39-
// TODO: Evaluate the need for this method as part of
40-
// https://redhat.atlassian.net/browse/HYPERFLEET-1085 and remove if not needed
41-
func (l ResourceList) Index() ResourceIndex {
42-
index := ResourceIndex{}
43-
for _, o := range l {
44-
index[o.ID] = o
45-
}
46-
return index
34+
type ResourcePatchRequest struct {
35+
Spec *map[string]interface{} `json:"spec,omitempty"`
36+
Labels *map[string]string `json:"labels,omitempty"`
4737
}
4838

39+
type ResourceList []*Resource
40+
4941
func (r Resource) TableName() string {
5042
return "resources"
5143
}
5244

53-
// BeforeCreate TODO: Validate the necessity for this as part of https://redhat.atlassian.net/browse/HYPERFLEET-1085
5445
func (r *Resource) BeforeCreate(tx *gorm.DB) error {
5546
if r.ID == "" {
5647
id, err := NewID()

pkg/api/resource_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,6 @@ func strPtr(s string) *string {
2626
return &s
2727
}
2828

29-
func TestResourceList_Index(t *testing.T) {
30-
RegisterTestingT(t)
31-
32-
emptyList := ResourceList{}
33-
emptyIndex := emptyList.Index()
34-
Expect(len(emptyIndex)).To(Equal(0))
35-
36-
r1 := &Resource{}
37-
r1.ID = "res-1"
38-
r1.Name = "test-resource-1"
39-
40-
r2 := &Resource{}
41-
r2.ID = "res-2"
42-
r2.Name = "test-resource-2"
43-
44-
multiList := ResourceList{r1, r2}
45-
multiIndex := multiList.Index()
46-
Expect(len(multiIndex)).To(Equal(2))
47-
Expect(multiIndex["res-1"]).To(Equal(r1))
48-
Expect(multiIndex["res-2"]).To(Equal(r2))
49-
50-
r1Dup := &Resource{}
51-
r1Dup.ID = "res-1"
52-
r1Dup.Name = "duplicate"
53-
54-
dupList := ResourceList{r1, r1Dup}
55-
dupIndex := dupList.Index()
56-
Expect(len(dupIndex)).To(Equal(1))
57-
Expect(dupIndex["res-1"].Name).To(Equal("duplicate"))
58-
}
59-
6029
func TestResource_BeforeCreate_IDGeneration(t *testing.T) {
6130
RegisterTestingT(t)
6231
setupTestRegistry()

pkg/registry/descriptor.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ type EntityDescriptor struct {
1717
SpecSchemaName string // OpenAPI component name for spec validation
1818
OnParentDelete OnParentDeletePolicy // only meaningful when ParentKind != ""
1919
SearchDisallowedFields []string // fields blocked from TSL search
20-
NameMinLen int // minimum name length
21-
NameMaxLen int // maximum name length
2220
}

pkg/registry/registry.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ func ChildrenOf(parentKind string) []EntityDescriptor {
5656
// Validate checks registry integrity. Panics on:
5757
// - empty Kind or Plural on any descriptor
5858
// - any ParentKind that references an unregistered kind
59-
// - NameMinLen > NameMaxLen (when NameMaxLen is set)
6059
// - duplicate Plural values across descriptors
6160
func Validate() {
6261
plurals := make(map[string]string, len(descriptors))
@@ -78,13 +77,6 @@ func Validate() {
7877
}
7978
}
8079

81-
if d.NameMaxLen > 0 && d.NameMinLen > d.NameMaxLen {
82-
panic(fmt.Sprintf(
83-
"entity kind %q has NameMinLen (%d) > NameMaxLen (%d)",
84-
d.Kind, d.NameMinLen, d.NameMaxLen,
85-
))
86-
}
87-
8880
if existing, ok := plurals[d.Plural]; ok {
8981
panic(fmt.Sprintf(
9082
"duplicate plural %q: registered by both %q and %q",

pkg/registry/registry_test.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ func TestRegister_Success(t *testing.T) {
1111
Reset()
1212

1313
d := EntityDescriptor{
14-
Kind: "Channel",
15-
Plural: "channels",
16-
NameMinLen: 3,
17-
NameMaxLen: 53,
14+
Kind: "Channel",
15+
Plural: "channels",
1816
}
1917

2018
Register(d)
@@ -23,8 +21,6 @@ func TestRegister_Success(t *testing.T) {
2321
Expect(ok).To(BeTrue())
2422
Expect(got.Kind).To(Equal("Channel"))
2523
Expect(got.Plural).To(Equal("channels"))
26-
Expect(got.NameMinLen).To(Equal(3))
27-
Expect(got.NameMaxLen).To(Equal(53))
2824
}
2925

3026
func TestRegister_DuplicateKind_Panics(t *testing.T) {
@@ -140,17 +136,6 @@ func TestRegister_EmptyPlural_Panics(t *testing.T) {
140136
}).To(PanicWith(ContainSubstring("has empty plural")))
141137
}
142138

143-
func TestValidate_NameMinExceedsMax_Panics(t *testing.T) {
144-
RegisterTestingT(t)
145-
Reset()
146-
147-
Register(EntityDescriptor{Kind: "Channel", Plural: "channels", NameMinLen: 100, NameMaxLen: 3})
148-
149-
Expect(func() {
150-
Validate()
151-
}).To(PanicWith(ContainSubstring("NameMinLen (100) > NameMaxLen (3)")))
152-
}
153-
154139
func TestValidate_Success(t *testing.T) {
155140
RegisterTestingT(t)
156141
Reset()
@@ -179,8 +164,6 @@ func TestDescriptorFields(t *testing.T) {
179164
Register(EntityDescriptor{
180165
Kind: "Version",
181166
Plural: "versions",
182-
NameMinLen: 3,
183-
NameMaxLen: 53,
184167
ParentKind: "Channel",
185168
OnParentDelete: OnParentDeleteRestrict,
186169
SpecSchemaName: "VersionSpec",

0 commit comments

Comments
 (0)