Skip to content

Commit

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

// 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 +306,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 +319,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 +342,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
24 changes: 21 additions & 3 deletions apis/admission/v1/zz_generated.die.go

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

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
15 changes: 12 additions & 3 deletions apis/admissionregistration/v1/mutatingwebhookconfiguration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ func TestMutatingWebhookConfiguration(t *testing.T) {
expected admissionregistrationv1.MutatingWebhookConfiguration
}{
{
name: "empty",
die: dieadmissionregistrationv1.MutatingWebhookConfigurationBlank,
expected: admissionregistrationv1.MutatingWebhookConfiguration{},
name: "empty",
die: dieadmissionregistrationv1.MutatingWebhookConfigurationBlank,
expected: admissionregistrationv1.MutatingWebhookConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: "admissionregistration.k8s.io/v1",
Kind: "MutatingWebhookConfiguration",
},
},
},
{
name: "object metadata",
Expand All @@ -44,6 +49,10 @@ func TestMutatingWebhookConfiguration(t *testing.T) {
d.Name("my-name")
}),
expected: admissionregistrationv1.MutatingWebhookConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: "admissionregistration.k8s.io/v1",
Kind: "MutatingWebhookConfiguration",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-name",
},
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ func TestValidatingWebhookConfiguration(t *testing.T) {
expected admissionregistrationv1.ValidatingWebhookConfiguration
}{
{
name: "empty",
die: dieadmissionregistrationv1.ValidatingWebhookConfigurationBlank,
expected: admissionregistrationv1.ValidatingWebhookConfiguration{},
name: "empty",
die: dieadmissionregistrationv1.ValidatingWebhookConfigurationBlank,
expected: admissionregistrationv1.ValidatingWebhookConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: "admissionregistration.k8s.io/v1",
Kind: "ValidatingWebhookConfiguration",
},
},
},
{
name: "object metadata",
Expand All @@ -44,6 +49,10 @@ func TestValidatingWebhookConfiguration(t *testing.T) {
d.Name("my-name")
}),
expected: admissionregistrationv1.ValidatingWebhookConfiguration{
TypeMeta: metav1.TypeMeta{
APIVersion: "admissionregistration.k8s.io/v1",
Kind: "ValidatingWebhookConfiguration",
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-name",
},
Expand Down
Loading

0 comments on commit d45d469

Please sign in to comment.