Skip to content

Commit

Permalink
Add Invitation manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
bastjan committed Feb 6, 2023
1 parent 37b1020 commit efde6f6
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apis/user/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -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
)
121 changes: 121 additions & 0 deletions apis/user/v1/invitation_types.go
Original file line number Diff line number Diff line change
@@ -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{})
}
128 changes: 128 additions & 0 deletions apis/user/v1/zz_generated.deepcopy.go

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

0 comments on commit efde6f6

Please sign in to comment.