Skip to content

Commit

Permalink
feat(app): impl creation form crd, update app crds (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow authored Sep 15, 2022
1 parent b3cb361 commit 802aa0e
Show file tree
Hide file tree
Showing 31 changed files with 858 additions and 340 deletions.
11 changes: 10 additions & 1 deletion controllers/application/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ resources:
controller: true
domain: laf.dev
group: application
kind: Specification
kind: Bundle
path: github.com/labring/laf/controllers/application/api/v1
version: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: laf.dev
group: application
kind: CreationForm
path: github.com/labring/laf/controllers/application/api/v1
version: v1
version: "3"
59 changes: 34 additions & 25 deletions controllers/application/api/v1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,28 @@ import (
type ApplicationState string

const (
ApplicationStateCreated ApplicationState = "Created"
ApplicationStateStarted ApplicationState = "Started"
ApplicationStateStopped ApplicationState = "Stopped"
ApplicationStateRunning ApplicationState = "Running"
ApplicationStateRestarted ApplicationState = "Restarted"
ApplicationStateDeleted ApplicationState = "Deleted"
ApplicationStateInitializing ApplicationState = "Initializing"
ApplicationStateInitialized ApplicationState = "Initialized"
ApplicationStateStarting ApplicationState = "Starting"
ApplicationStateRunning ApplicationState = "Running"
ApplicationStateStopping ApplicationState = "Stopping"
ApplicationStateStopped ApplicationState = "Stopped"
)

// ApplicationSpec defines the desired state of Application
type ApplicationSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// DisplayName for the application
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=63
//+kubebuilder:validation:Required
DisplayName string `json:"displayName"`

// State of the application
//+kubebuilder:validation:Enum=Created;Started;Stopped;Running;Restarted;Deleted
//+kubebuilder:validation:Enum=Running;Stopped;
//+kubebuilder:validation:Required
//+kubebuilder:default:=Created
State ApplicationState `json:"state"`
//+kubebuilder:default:=Running
State ApplicationState `json:"state,omitempty"`

// Specification Name for the application
// Bundle Name for the application
//+kubebuilder:validation:Required
SpecificationName string `json:"specificationName"`
BundleName string `json:"bundleName"`

// Runtime Name of the application
//+kubebuilder:validation:Required
Expand All @@ -69,18 +63,33 @@ type ApplicationStatus struct {

// AppId
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=16
//+kubebuilder:validation:MaxLength=24
//+kubebuilder:validation:Required
AppId string `json:"appid"`

// Specification for the application
Specification SpecificationSpec `json:"specification"`

// State of the application
State ApplicationState `json:"state"`

// Runtime for the application
Runtime v1.RuntimeSpec `json:"runtime"`
Phase ApplicationState `json:"state,omitempty"`

// Bundle of the application
Bundle BundleSpec `json:"bundle,omitempty"`

// Runtime of the application
Runtime v1.RuntimeSpec `json:"runtime,omitempty"`

// Conditions:
// - type: DatabaseCreated
// status: True | False | Unknown
// reason: "DatabaseCreated" | "InsufficientResources" | "Unknown"
// message: "Database created Successfully" | "Insufficient resources to create database" | "Unknown error"
// - type: ObjectStorageCreated
// - type: GatewayCreated
// - type: InstanceCreated
// - type: InstanceReady
// - type: InstanceDeleted
// - type: DatabaseDeleted
// - type: ObjectStorageDeleted
// - type: GatewayDeleted
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,76 +24,76 @@ import (
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// SpecificationSpec defines the desired state of Specification
type SpecificationSpec struct {
// BundleSpec defines the desired state of Bundle
type BundleSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// DisplayName for the specification
// DisplayName for the bundle
DisplayName string `json:"displayName"`

// Request CPU for the specification
// Request CPU for the bundle
RequestCPU resource.Quantity `json:"requestCPU"`

// Request Memory for the specification
// Request Memory for the bundle
RequestMemory resource.Quantity `json:"requestMemory"`

// Limit CPU for the specification
// Limit CPU for the bundle
LimitCPU resource.Quantity `json:"limitCPU"`

// Limit Memory for the specification
// Limit Memory for the bundle
LimitMemory resource.Quantity `json:"limitMemory"`

// Database capacity for the specification
// Database capacity for the bundle
DatabaseCapacity resource.Quantity `json:"databaseCapacity"`

// Storage capacity for the specification
// Storage capacity for the bundle
StorageCapacity resource.Quantity `json:"storageCapacity"`

// Network Bandwidth Outbound for the specification
// Network Bandwidth Outbound for the bundle
NetworkBandwidthOutbound resource.Quantity `json:"networkBandwidthOutbound,omitempty"`

// Network Bandwidth Inbound for the specification
// Network Bandwidth Inbound for the bundle
NetworkBandwidthInbound resource.Quantity `json:"networkBandwidthInbound,omitempty"`

// Network Traffic Outbound for the specification
// Network Traffic Outbound for the bundle
NetworkTrafficOutbound resource.Quantity `json:"networkTrafficOutbound"`

// Priority for the specification.
// The default value is 0, which means that the specification is not currently available for creating new applications.
// Priority for the bundle.
// The default value is 0, which means that the bundle is not currently available for creating new applications.
//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Maximum=1000
//+kubebuilder:validation:Default=10
Priority int32 `json:"priority"`
}

// SpecificationStatus defines the observed state of Specification
type SpecificationStatus struct {
// BundleStatus defines the observed state of Bundle
type BundleStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Specification is the Schema for the specifications API
type Specification struct {
// Bundle is the Schema for the bundles API
type Bundle struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SpecificationSpec `json:"spec,omitempty"`
Status SpecificationStatus `json:"status,omitempty"`
Spec BundleSpec `json:"spec,omitempty"`
Status BundleStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// SpecificationList contains a list of Specification
type SpecificationList struct {
// BundleList contains a list of Bundle
type BundleList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Specification `json:"items"`
Items []Bundle `json:"items"`
}

func init() {
SchemeBuilder.Register(&Specification{}, &SpecificationList{})
SchemeBuilder.Register(&Bundle{}, &BundleList{})
}
81 changes: 81 additions & 0 deletions controllers/application/api/v1/creationform_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2022.
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://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 (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// CreationFormSpec defines the desired state of CreationForm
type CreationFormSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// DisplayName for the application
//+kubebuilder:validation:MinLength=3
//+kubebuilder:validation:MaxLength=63
//+kubebuilder:validation:Required
DisplayName string `json:"displayName"`

// Bundle Name for the application
//+kubebuilder:validation:Required
BundleName string `json:"bundleName"`

// Runtime Name of the application
//+kubebuilder:validation:Required
RuntimeName string `json:"runtimeName"`
}

// CreationFormStatus defines the observed state of CreationForm
type CreationFormStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

AppId string `json:"appid,omitempty"`

Namespace string `json:"namespace,omitempty"`

Created bool `json:"created,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// CreationForm is the Schema for the creationforms API
type CreationForm struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CreationFormSpec `json:"spec,omitempty"`
Status CreationFormStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// CreationFormList contains a list of CreationForm
type CreationFormList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CreationForm `json:"items"`
}

func init() {
SchemeBuilder.Register(&CreationForm{}, &CreationFormList{})
}
Loading

0 comments on commit 802aa0e

Please sign in to comment.