From efde6f6fd636751d21e7c146abf39e087fd90453 Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Mon, 6 Feb 2023 09:59:14 +0100 Subject: [PATCH] Add `Invitation` manifest --- apis/user/v1/groupversion_info.go | 21 +++++ apis/user/v1/invitation_types.go | 121 ++++++++++++++++++++++++ apis/user/v1/zz_generated.deepcopy.go | 128 ++++++++++++++++++++++++++ 3 files changed, 270 insertions(+) create mode 100644 apis/user/v1/groupversion_info.go create mode 100644 apis/user/v1/invitation_types.go create mode 100644 apis/user/v1/zz_generated.deepcopy.go diff --git a/apis/user/v1/groupversion_info.go b/apis/user/v1/groupversion_info.go new file mode 100644 index 00000000..fc2495f0 --- /dev/null +++ b/apis/user/v1/groupversion_info.go @@ -0,0 +1,21 @@ +// Package v1 contains API Schema definitions for the control-api v1 API group +// +kubebuilder:object:generate=true +// +kubebuilder:skip +// +groupName=user.appuio.io +package v1 + +import ( + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/controller-runtime/pkg/scheme" +) + +var ( + // GroupVersion is group version used to register these objects + GroupVersion = schema.GroupVersion{Group: "user.appuio.io", Version: "v1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} + + // AddToScheme adds the types in this group-version to the given scheme. + AddToScheme = SchemeBuilder.AddToScheme +) diff --git a/apis/user/v1/invitation_types.go b/apis/user/v1/invitation_types.go new file mode 100644 index 00000000..cbc769d9 --- /dev/null +++ b/apis/user/v1/invitation_types.go @@ -0,0 +1,121 @@ +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "sigs.k8s.io/apiserver-runtime/pkg/builder/resource" +) + +const ( + // ConditionRedeemed is set when the invitation has been redeemed + ConditionRedeemed = "Redeemed" + // ConditionEmailSent is set when the invitation email has been sent + ConditionEmailSent = "EmailSent" +) + +// +kubebuilder:object:root=true + +// Invitation is a representation of an APPUiO Cloud Invitation +type Invitation struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec holds the desired invitation state + Spec InvitationSpec `json:"spec,omitempty"` + // Status holds the invitation specific status + Status InvitationStatus `json:"status,omitempty"` +} + +// InvitationSpec defines the desired state of the Invitation +type InvitationSpec struct { + // Note is a free-form text field to add a note to the invitation + Note string `json:"note,omitempty"` + // Email is the email address of the invited user, used to send the invitation + Email string `json:"email,omitempty"` + // TargetRefs is a list of references to the target resources + TargetRefs []TargetRef `json:"targetRefs,omitempty"` +} + +// TargetRef is a reference to a target resource +type TargetRef struct { + // APIGroup is the API group of the target resource + APIGroup string `json:"apiGroup,omitempty"` + // Kind is the kind of the target resource + Kind string `json:"kind,omitempty"` + // Name is the name of the target resource + Name string `json:"name,omitempty"` + // Namespace is the namespace of the target resource + Namespace string `json:"namespace,omitempty"` +} + +// InvitationStatus defines the observed state of the Invitation +type InvitationStatus struct { + // Token is the invitation token + Token string `json:"token,omitempty"` + // ValidUntil is the time when the invitation expires + ValidUntil metav1.Time `json:"validUntil,omitempty"` + // Conditions is a list of conditions for the invitation + Conditions []metav1.Condition `json:"conditions,omitempty"` +} + +// Invitation needs to implement the builder resource interface +var _ resource.Object = &Invitation{} + +// GetObjectMeta returns the objects meta reference. +func (o *Invitation) GetObjectMeta() *metav1.ObjectMeta { + return &o.ObjectMeta +} + +// GetGroupVersionResource returns the GroupVersionResource for this resource. +// The resource should be the all lowercase and pluralized kind +func (o *Invitation) GetGroupVersionResource() schema.GroupVersionResource { + return schema.GroupVersionResource{ + Group: GroupVersion.Group, + Version: GroupVersion.Version, + Resource: "invitations", + } +} + +// IsStorageVersion returns true if the object is also the internal version -- i.e. is the type defined for the API group or an alias to this object. +// If false, the resource is expected to implement MultiVersionObject interface. +func (o *Invitation) IsStorageVersion() bool { + return true +} + +// NamespaceScoped returns true if the object is namespaced +func (o *Invitation) NamespaceScoped() bool { + return false +} + +// New returns a new instance of the resource +func (o *Invitation) New() runtime.Object { + return &Invitation{} +} + +// NewList return a new list instance of the resource +func (o *Invitation) NewList() runtime.Object { + return &InvitationList{} +} + +// +kubebuilder:object:root=true + +// InvitationList contains a list of Invitations +type InvitationList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + + Items []Invitation `json:"items"` +} + +// InvitationList needs to implement the builder resource interface +var _ resource.ObjectList = &InvitationList{} + +// GetListMeta returns the list meta reference. +func (in *InvitationList) GetListMeta() *metav1.ListMeta { + return &in.ListMeta +} + +func init() { + SchemeBuilder.Register(&Invitation{}, &InvitationList{}) +} diff --git a/apis/user/v1/zz_generated.deepcopy.go b/apis/user/v1/zz_generated.deepcopy.go new file mode 100644 index 00000000..c79269e2 --- /dev/null +++ b/apis/user/v1/zz_generated.deepcopy.go @@ -0,0 +1,128 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Invitation) DeepCopyInto(out *Invitation) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Invitation. +func (in *Invitation) DeepCopy() *Invitation { + if in == nil { + return nil + } + out := new(Invitation) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Invitation) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InvitationList) DeepCopyInto(out *InvitationList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Invitation, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InvitationList. +func (in *InvitationList) DeepCopy() *InvitationList { + if in == nil { + return nil + } + out := new(InvitationList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *InvitationList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InvitationSpec) DeepCopyInto(out *InvitationSpec) { + *out = *in + if in.TargetRefs != nil { + in, out := &in.TargetRefs, &out.TargetRefs + *out = make([]TargetRef, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InvitationSpec. +func (in *InvitationSpec) DeepCopy() *InvitationSpec { + if in == nil { + return nil + } + out := new(InvitationSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *InvitationStatus) DeepCopyInto(out *InvitationStatus) { + *out = *in + in.ValidUntil.DeepCopyInto(&out.ValidUntil) + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]metav1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InvitationStatus. +func (in *InvitationStatus) DeepCopy() *InvitationStatus { + if in == nil { + return nil + } + out := new(InvitationStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TargetRef) DeepCopyInto(out *TargetRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TargetRef. +func (in *TargetRef) DeepCopy() *TargetRef { + if in == nil { + return nil + } + out := new(TargetRef) + in.DeepCopyInto(out) + return out +}