Skip to content

Commit

Permalink
rename ObjectAPIVersion to ObjectVersion because it was not the APIVe…
Browse files Browse the repository at this point in the history
…rsion

APIVersion = ObjectGroup() + '/' + ObjectVersion()
  • Loading branch information
jlarfors committed Feb 27, 2024
1 parent 4c1f7bc commit 7ac8f6c
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 23 deletions.
4 changes: 3 additions & 1 deletion examples/greetings/greetings.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package greetings

import "github.com/verifa/horizon/pkg/hz"

var _ hz.Objecter = (*Greeting)(nil)

type Greeting struct {
hz.ObjectMeta `json:"metadata"`

Spec GreetingSpec `json:"spec"`
Status GreetingStatus `json:"status"`
}

func (s Greeting) ObjectAPIVersion() string {
func (s Greeting) ObjectVersion() string {
return "v1"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Role struct {
Spec RoleSpec `json:"spec,omitempty" cue:""`
}

func (Role) ObjectAPIVersion() string {
func (Role) ObjectVersion() string {
return "v1"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/auth/rolebinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type RoleBinding struct {
Spec RoleBindingSpec `json:"spec,omitempty" cue:""`
}

func (RoleBinding) ObjectAPIVersion() string {
func (RoleBinding) ObjectVersion() string {
return "v1"
}

Expand Down
6 changes: 4 additions & 2 deletions pkg/broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DummyObject struct {
Status struct{} `json:"status,omitempty"`
}

func (o DummyObject) ObjectAPIVersion() string {
func (o DummyObject) ObjectVersion() string {
return "v1"
}

Expand Down Expand Up @@ -62,14 +62,16 @@ func (a timeoutAction) Do(
return obj, nil
}

var _ (hz.Objecter) = (*returnIDObject)(nil)

type returnIDObject struct {
hz.ObjectMeta `json:"metadata,omitempty"`

Spec returnIDSpec `json:"spec"`
Status returnIDStatus `json:"status"`
}

func (n returnIDObject) ObjectAPIVersion() string {
func (n returnIDObject) ObjectVersion() string {
return "v1"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/extensions/accounts/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Account struct {
Status *AccountStatus `json:"status,omitempty"`
}

func (a Account) ObjectAPIVersion() string {
func (a Account) ObjectVersion() string {
return "v1"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/extensions/accounts/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Member struct {
Spec MemberSpec `json:"spec,omitempty" cue:""`
}

func (Member) ObjectAPIVersion() string {
func (Member) ObjectVersion() string {
return "v1"
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/extensions/accounts/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/verifa/horizon/pkg/natsutil"
)

var _ (hz.Objecter) = (*User)(nil)

// User represents a NATS user.
type User struct {
hz.ObjectMeta `json:"metadata"`
Expand All @@ -18,7 +20,7 @@ type User struct {
Status UserStatus `json:"status"`
}

func (u User) ObjectAPIVersion() string {
func (u User) ObjectVersion() string {
return "v1"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/hz/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ func (c Client) marshalObjectWithTypeFields(obj Objecter) ([]byte, error) {
data, err = sjson.SetBytes(
data,
"apiVersion",
fmt.Sprintf("%s/%s", obj.ObjectGroup(), obj.ObjectAPIVersion()),
fmt.Sprintf("%s/%s", obj.ObjectGroup(), obj.ObjectVersion()),
)
if err != nil {
return nil, fmt.Errorf("setting apiVersion: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/hz/cue.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func cueSpecFromObject(cCtx *cue.Context, obj Objecter) (cue.Value, error) {
return cue.Value{}, fmt.Errorf("compiling kind expression: %w", err)
}
apiVersionExpr := cCtx.CompileString(
fmt.Sprintf("=~\"^%s/%s$\"", obj.ObjectGroup(), obj.ObjectAPIVersion()),
fmt.Sprintf("=~\"^%s/%s$\"", obj.ObjectGroup(), obj.ObjectVersion()),
)
if err := apiVersionExpr.Err(); err != nil {
return cue.Value{}, fmt.Errorf(
Expand Down
2 changes: 1 addition & 1 deletion pkg/hz/cue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (s cueObj) ObjectGroup() string {
return "CueGroup"
}

func (s cueObj) ObjectAPIVersion() string {
func (s cueObj) ObjectVersion() string {
return "v1"
}

Expand Down
4 changes: 3 additions & 1 deletion pkg/hz/managedfields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestExtractObjectFields(t *testing.T) {
tu.AssertEqual(t, idObj, idObjManagedFields, cmpOptIgnoreMetaManagedFields)
}

var _ hz.Objecter = (*extractFieldsObject)(nil)

type extractFieldsObject struct {
hz.ObjectMeta `json:"metadata,omitempty"`

Expand All @@ -86,6 +88,6 @@ func (o extractFieldsObject) ObjectGroup() string {
return "extractFieldsGroup"
}

func (o extractFieldsObject) ObjectAPIVersion() string {
func (o extractFieldsObject) ObjectVersion() string {
return "v1"
}
15 changes: 8 additions & 7 deletions pkg/hz/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Objecter interface {
ObjectOwnerReferences() []OwnerReference
ObjectOwnerReference(Objecter) (OwnerReference, bool)
ObjectManagedFields() managedfields.ManagedFields
ObjectAPIVersion() string
ObjectVersion() string
}

// ObjectKeyer is an interface that can produce a unique key for an object.
Expand Down Expand Up @@ -259,10 +259,11 @@ var _ Objecter = (*GenericObject)(nil)
type GenericObject struct {
ObjectMeta `json:"metadata,omitempty"`

APIVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty"`
Spec json.RawMessage `json:"spec,omitempty"`
Status json.RawMessage `json:"status,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
Kind string `json:"kind,omitempty"`

Spec json.RawMessage `json:"spec,omitempty"`
Status json.RawMessage `json:"status,omitempty"`
}

func (r GenericObject) ObjectKind() string {
Expand All @@ -277,7 +278,7 @@ func (r GenericObject) ObjectGroup() string {
return parts[0]
}

func (r GenericObject) ObjectAPIVersion() string {
func (r GenericObject) ObjectVersion() string {
parts := strings.Split(r.APIVersion, "/")
if len(parts) != 2 {
return ""
Expand Down Expand Up @@ -316,6 +317,6 @@ func (r MetaOnlyObject) ObjectGroup() string {
return r.Group
}

func (r MetaOnlyObject) ObjectAPIVersion() string {
func (r MetaOnlyObject) ObjectVersion() string {
return r.APIVersion
}
4 changes: 2 additions & 2 deletions pkg/hz/object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (o DummyObject) ObjectGroup() string {
return "DummyGroup"
}

func (o DummyObject) ObjectAPIVersion() string {
func (o DummyObject) ObjectVersion() string {
return "v1"
}

Expand All @@ -39,6 +39,6 @@ func (o ChildObject) ObjectGroup() string {
return "ChildGroup"
}

func (o ChildObject) ObjectAPIVersion() string {
func (o ChildObject) ObjectVersion() string {
return "v1"
}
2 changes: 1 addition & 1 deletion pkg/hz/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Portal struct {
Status PortalStatus `json:"status,omitempty"`
}

func (e Portal) ObjectAPIVersion() string {
func (e Portal) ObjectVersion() string {
return "v1"
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/store/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type DummyApplyObject struct {
Spec struct{} `json:"spec"`
}

func (r DummyApplyObject) ObjectAPIVersion() string {
func (r DummyApplyObject) ObjectVersion() string {
return "v1"
}

Expand Down

0 comments on commit 7ac8f6c

Please sign in to comment.