Skip to content

Commit

Permalink
Default APIVersion and Kind for objects (#146)
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Andrews <scott@andrews.me>
  • Loading branch information
scothis authored Jun 11, 2024
1 parent 8e5d072 commit 65f57ab
Show file tree
Hide file tree
Showing 81 changed files with 1,853 additions and 224 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,30 @@ type MyResourceDie interface {
// unstructured object.
DieReleaseUnstructured() *unstructured.Unstructured

// DieDefaultTypeMetadata sets the APIVersion and Kind
DieDefaultTypeMetadata() *MyResourceDie

// APIVersion defines the versioned schema of this representation of an
// object. Servers should convert recognized schemas to the latest internal
// value, and may reject unrecognized values. More info:
// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
APIVersion(v string) *MyResourceDie

// Kind is a string value representing the REST resource this object
// represents. Servers may infer this from the endpoint the client submits
// requests to. Cannot be updated. In CamelCase. More info:
// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
Kind(v string) *MyResourceDie

// TypeMetadata standard object's type metadata.
TypeMetadata(v metav1.TypeMeta) *MyResourceDie

// TypeMetaDie stamps the resource's TypeMeta field with a mutable die.
TypeMetaDie(fn func(d *diemetav1.TypeMetaDie)) *MyResourceDie

// Metadata standard object's metadata.
Metadata(v metav1.ObjectMeta) *MyResourceDie

// MetadataDie stamps the resource's ObjectMeta field with a mutable die.
MetadataDie(fn func(d *diemetav1.ObjectMetaDie)) *MyResourceDie

Expand Down Expand Up @@ -285,7 +309,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
)

// +die:object=true
// +die:object=true,apiVersion=apps/v1,kind=Deployment
type _ = appsv1.Deployment

// +die
Expand All @@ -298,7 +322,7 @@ type _ = appsv1.DeploymentStatus
For packages you control, dies can be created in the same package as the resource they model by adding the markers to existing types.

```go
// +die:object=true
// +die:object=true,apiVersion=example.reconciler.io/v1,kind=MyResource
type MyResource struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -321,4 +345,6 @@ type MyResourceStatus struct {

Properties:
- **object** `bool` (optional): indicates the target type implements `metav1.Object` and `runtime.Object`
- **apiVersion** `string` (optional): defaults the blanks die's APIVersion (only for objects)
- **kind** `string` (optional): defaults the blank die's Kind (only for objects)
- **ignore** `[]string` (optional): set of fields to ignore on the type
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
diemetav1 "reconciler.io/dies/apis/meta/v1"
)

// +die:object=true
// +die:object=true,apiVersion=admissionregistration.k8s.io/v1,kind=MutatingWebhookConfiguration
type _ = admissionregistrationv1.MutatingWebhookConfiguration

func (d *MutatingWebhookConfigurationDie) WebhookDie(name string, fn func(d *MutatingWebhookDie)) *MutatingWebhookConfigurationDie {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
diemetav1 "reconciler.io/dies/apis/meta/v1"
)

// +die:object=true
// +die:object=true,apiVersion=admissionregistration.k8s.io/v1,kind=ValidatingWebhookConfiguration
type _ = admissionregistrationv1.ValidatingWebhookConfiguration

func (d *ValidatingWebhookConfigurationDie) WebhookDie(name string, fn func(d *ValidatingWebhookDie)) *ValidatingWebhookConfigurationDie {
Expand Down
68 changes: 62 additions & 6 deletions apis/admissionregistration/v1/zz_generated.die.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/apiextensions/v1/customresourcedefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
diemetav1 "reconciler.io/dies/apis/meta/v1"
)

// +die:object=true
// +die:object=true,apiVersion=apiextensions.k8s.io/v1,kind=CustomResourceDefinition
type _ = apiextensionsv1.CustomResourceDefinition

// +die
Expand Down
35 changes: 32 additions & 3 deletions apis/apiextensions/v1/zz_generated.die.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/apiregistration/v1/apiservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
diemetav1 "reconciler.io/dies/apis/meta/v1"
)

// +die:object=true
// +die:object=true,apiVersion=apiregistration.k8s.io/v1,kind=APIService
type _ = apiregistrationv1.APIService

// +die
Expand Down
35 changes: 32 additions & 3 deletions apis/apiregistration/v1/zz_generated.die.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apis/apiserver/flowcontrol/v1beta1/flowschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
diemetav1 "reconciler.io/dies/apis/meta/v1"
)

// +die:object=true
// +die:object=true,apiVersion=flowcontrol.apiserver.k8s.io/v1beta1,kind=FlowSchema
type _ = flowcontrolv1beta1.FlowSchema

// +die
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
diemetav1 "reconciler.io/dies/apis/meta/v1"
)

// +die:object=true
// +die:object=true,apiVersion=flowcontrol.apiserver.k8s.io/v1beta1,kind=PriorityLevelConfiguration
type _ = flowcontrolv1beta1.PriorityLevelConfiguration

// +die
Expand Down
Loading

0 comments on commit 65f57ab

Please sign in to comment.