-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invitation API and Storage #98
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
efde6f6
Add `Invitation` manifest
bastjan a043535
Generic storage using secrets as backing + Invitation resource plumbing
bastjan 6e6b873
Status updates
bastjan f99eb8f
Create redemption token in Invitation.status
bastjan 72c593a
Move common controller setup method to its own file
bastjan 9c884cc
fix typo
bastjan 2aff93a
Allow apiserver to access secrets
bastjan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
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" | ||
|
||
"github.com/appuio/control-api/apiserver/secretstorage/status" | ||
) | ||
|
||
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"` | ||
// ValidUntil is the time when the invitation expires | ||
ValidUntil metav1.Time `json:"validUntil"` | ||
// Conditions is a list of conditions for the invitation | ||
Conditions []metav1.Condition `json:"conditions"` | ||
} | ||
|
||
// Invitation needs to implement the builder resource interface | ||
var _ status.ObjectWithStatusSubResource = &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{} | ||
} | ||
|
||
// SecretStorageGetStatus returns the status of the resource | ||
func (o *Invitation) SecretStorageGetStatus() status.StatusSubResource { | ||
return &o.Status | ||
} | ||
|
||
// CopyTo copies the status to the given parent resource | ||
func (s *InvitationStatus) SecretStorageCopyTo(parent status.ObjectWithStatusSubResource) { | ||
parent.(*Invitation).Status = *s.DeepCopy() | ||
} | ||
|
||
func (s InvitationStatus) SubResourceName() string { | ||
return "status" | ||
} | ||
|
||
// +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{}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably a good reason why we define
TargetRef
ourselves, but I'm wondering if we could just use the standardObjectReference
type instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason was looking into the
RoleBinding
subjects instead of other references. Those don't have the right documentation when generated.Using
ObjectReference
seems like a good idea but will introduce more validation overhead since there are more fields to respect and we'll most likely never use any of them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with having our own ref type especially since that will give us flexibility if we figure out that we need something that we can't get from
ObjectReference
. Additionally, there seems to be no clear consensus even in the core K8s types on whether you're supposed to useLocalObjectReference
/ObjectReference
vs your own ref types