-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from appuio/feat/organizations
Add Organization type
- Loading branch information
Showing
24 changed files
with
2,200 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ exclude_patterns: | |
- '**/*.d.ts' | ||
- 'e2e/lib/' | ||
- '**/zz_generated.deepcopy.go' | ||
- '**/mock/' |
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 |
---|---|---|
|
@@ -34,3 +34,6 @@ crd*.yaml | |
|
||
# Go releaser | ||
dist/ | ||
|
||
# apiserver-runtime | ||
apiserver.local.config/ |
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=organization.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: "organization.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,131 @@ | ||
package v1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
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" | ||
) | ||
|
||
var ( | ||
// TypeKey is the label key to identify organization namespaces | ||
TypeKey = "appuio.io/resource.type" | ||
// OrgType is the label value to identify organization namespaces | ||
OrgType = "organization" | ||
// DisplayNameKey is the annotation key that stores the display name | ||
DisplayNameKey = "organization.appuio.io/display-name" | ||
) | ||
|
||
// NewOrganizationFromNS returns an Organization based on the given namespace | ||
// If the namespace does not represent an organization it will return nil | ||
func NewOrganizationFromNS(ns *corev1.Namespace) *Organization { | ||
if ns == nil || ns.Labels == nil || ns.Labels[TypeKey] != OrgType { | ||
return nil | ||
} | ||
displayName := "" | ||
if ns.Annotations != nil { | ||
displayName = ns.Annotations[DisplayNameKey] | ||
} | ||
org := &Organization{ | ||
ObjectMeta: *ns.ObjectMeta.DeepCopy(), | ||
Spec: OrganizationSpec{ | ||
DisplayName: displayName, | ||
}, | ||
} | ||
if org.Annotations != nil { | ||
delete(org.Annotations, DisplayNameKey) | ||
delete(org.Labels, TypeKey) | ||
} | ||
return org | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// Organization is a representation of an APPUiO Cloud Organization | ||
type Organization struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
// Spec holds the cluster specific metadata. | ||
Spec OrganizationSpec `json:"spec,omitempty"` | ||
} | ||
|
||
// OrganizationSpec defines the desired state of the Organization | ||
type OrganizationSpec struct { | ||
// DisplayName is a human-friendly name | ||
DisplayName string `json:"displayName,omitempty"` | ||
} | ||
|
||
// Organization needs to implement the builder resource interface | ||
var _ resource.Object = &Organization{} | ||
|
||
// GetObjectMeta returns the objects meta reference. | ||
func (o *Organization) 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 *Organization) GetGroupVersionResource() schema.GroupVersionResource { | ||
return schema.GroupVersionResource{ | ||
Group: GroupVersion.Group, | ||
Version: GroupVersion.Version, | ||
Resource: "organizations", | ||
} | ||
} | ||
|
||
// 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 *Organization) IsStorageVersion() bool { | ||
return true | ||
} | ||
|
||
// NamespaceScoped returns true if the object is namespaced | ||
func (o *Organization) NamespaceScoped() bool { | ||
return false | ||
} | ||
|
||
// New returns a new instance of the resource | ||
func (o *Organization) New() runtime.Object { | ||
return &Organization{} | ||
} | ||
|
||
// NewList return a new list instance of the resource | ||
func (o *Organization) NewList() runtime.Object { | ||
return &OrganizationList{} | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
|
||
// OrganizationList contains a list of Organizations | ||
type OrganizationList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
|
||
Items []Organization `json:"items"` | ||
} | ||
|
||
// OrganizationList needs to implement the builder resource interface | ||
var _ resource.ObjectList = &OrganizationList{} | ||
|
||
// GetListMeta returns the list meta reference. | ||
func (in *OrganizationList) GetListMeta() *metav1.ListMeta { | ||
return &in.ListMeta | ||
} | ||
|
||
// ToNamespace translates an Organization to the underlying namespace representation | ||
func (o *Organization) ToNamespace() *corev1.Namespace { | ||
ns := &corev1.Namespace{ | ||
ObjectMeta: *o.ObjectMeta.DeepCopy(), | ||
} | ||
if ns.Labels == nil { | ||
ns.Labels = map[string]string{} | ||
} | ||
if ns.Annotations == nil { | ||
ns.Annotations = map[string]string{} | ||
} | ||
ns.Labels[TypeKey] = OrgType | ||
ns.Annotations[DisplayNameKey] = o.Spec.DisplayName | ||
return ns | ||
} |
Oops, something went wrong.