Skip to content

Commit

Permalink
Add k8s.io/api/admission/v1 (#50)
Browse files Browse the repository at this point in the history
Also includes related metav1 types and adds support for retrieving and
feeding dies with runtime.RawExtension.

Signed-off-by: Scott Andrews <[email protected]>
  • Loading branch information
scothis committed Jun 13, 2022
1 parent 4e79155 commit 3f260fa
Show file tree
Hide file tree
Showing 37 changed files with 8,496 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,19 @@ type MyResourceDie interface {
// resource is nil, the empty value is used instead.
DieFeedPtr(r *MyResource) *MyResourceDie

// DieFeedRawExtension returns a new die with the provided raw extension.
DieFeedRawExtension(raw runtime.RawExtension) *MyResourceDie

// DieRelease returns the resource managed by the die.
DieRelease() MyResource

// DieReleasePtr returns a pointer to the resource managed by the die.
DieReleasePtr() *MyResource

// DieReleaseRawExtension returns the resource managed by the die as an
// raw extension.
DieReleaseRawExtension() runtime.RawExtension

// DieImmutable returns a new die for the current die's state that is
// either mutable (`false`) or immutable (`true`).
DieImmutable(immutable bool) *MyResourceDie
Expand Down
66 changes: 66 additions & 0 deletions apis/admission/v1/admissionrequest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2022 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
dieauthenticationv1 "dies.dev/apis/authentication/v1"
diemetav1 "dies.dev/apis/meta/v1"
admissionv1 "k8s.io/api/admission/v1"
)

// +die
type _ = admissionv1.AdmissionRequest

func (d *AdmissionRequestDie) KindDie(fn func(d *diemetav1.GroupVersionKindDie)) *AdmissionRequestDie {
return d.DieStamp(func(r *admissionv1.AdmissionRequest) {
d := diemetav1.GroupVersionKindBlank.DieImmutable(false).DieFeed(r.Kind)
fn(d)
r.Kind = d.DieRelease()
})
}

func (d *AdmissionRequestDie) ResourceDie(fn func(d *diemetav1.GroupVersionResourceDie)) *AdmissionRequestDie {
return d.DieStamp(func(r *admissionv1.AdmissionRequest) {
d := diemetav1.GroupVersionResourceBlank.DieImmutable(false).DieFeed(r.Resource)
fn(d)
r.Resource = d.DieRelease()
})
}

func (d *AdmissionRequestDie) RequestKindDie(fn func(d *diemetav1.GroupVersionKindDie)) *AdmissionRequestDie {
return d.DieStamp(func(r *admissionv1.AdmissionRequest) {
d := diemetav1.GroupVersionKindBlank.DieImmutable(false).DieFeedPtr(r.RequestKind)
fn(d)
r.RequestKind = d.DieReleasePtr()
})
}

func (d *AdmissionRequestDie) RequestResourceDie(fn func(d *diemetav1.GroupVersionResourceDie)) *AdmissionRequestDie {
return d.DieStamp(func(r *admissionv1.AdmissionRequest) {
d := diemetav1.GroupVersionResourceBlank.DieImmutable(false).DieFeedPtr(r.RequestResource)
fn(d)
r.RequestResource = d.DieReleasePtr()
})
}

func (d *AdmissionRequestDie) UserInfoDie(fn func(d *dieauthenticationv1.UserInfoDie)) *AdmissionRequestDie {
return d.DieStamp(func(r *admissionv1.AdmissionRequest) {
d := dieauthenticationv1.UserInfoBlank.DieImmutable(false).DieFeed(r.UserInfo)
fn(d)
r.UserInfo = d.DieRelease()
})
}
42 changes: 42 additions & 0 deletions apis/admission/v1/admissionresponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2022 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
diemetav1 "dies.dev/apis/meta/v1"
admissionv1 "k8s.io/api/admission/v1"
)

// +die
type _ = admissionv1.AdmissionResponse

func (d *AdmissionResponseDie) ResultDie(fn func(d *diemetav1.StatusDie)) *AdmissionResponseDie {
return d.DieStamp(func(r *admissionv1.AdmissionResponse) {
d := diemetav1.StatusBlank.DieImmutable(false).DieFeedPtr(r.Result)
fn(d)
r.Result = d.DieReleasePtr()
})
}

func (d *AdmissionResponseDie) AddAuditAnnotation(key, value string) *AdmissionResponseDie {
return d.DieStamp(func(r *admissionv1.AdmissionResponse) {
if r.AuditAnnotations == nil {
r.AuditAnnotations = map[string]string{}
}
r.AuditAnnotations[key] = value
})
}
40 changes: 40 additions & 0 deletions apis/admission/v1/admissionreview.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2022 the original author or authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
admissionv1 "k8s.io/api/admission/v1"
)

// +die
type _ = admissionv1.AdmissionReview

func (d *AdmissionReviewDie) RequestDie(fn func(d *AdmissionRequestDie)) *AdmissionReviewDie {
return d.DieStamp(func(r *admissionv1.AdmissionReview) {
d := AdmissionRequestBlank.DieImmutable(false).DieFeedPtr(r.Request)
fn(d)
r.Request = d.DieReleasePtr()
})
}

func (d *AdmissionReviewDie) ResponseDie(fn func(d *AdmissionResponseDie)) *AdmissionReviewDie {
return d.DieStamp(func(r *admissionv1.AdmissionReview) {
d := AdmissionResponseBlank.DieImmutable(false).DieFeedPtr(r.Response)
fn(d)
r.Response = d.DieReleasePtr()
})
}
Loading

0 comments on commit 3f260fa

Please sign in to comment.