Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Creating spec and status with additional markers/validation/printerCo…
…lumns
  • Loading branch information
an3l committed Dec 14, 2021
1 parent 7eb2b42 commit cd34e98
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 10 deletions.
60 changes: 54 additions & 6 deletions api/v1alpha1/mariadb_types.go
Expand Up @@ -25,21 +25,69 @@ import (

// MariaDBSpec defines the desired state of MariaDB
type MariaDBSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
// Size is the size of the deployment
// +optional
// +kubebuilder:validation:Required
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=4
Size int32 `json:"size"`

// Foo is an example field of MariaDB. Edit mariadb_types.go to remove/update
Foo string `json:"foo,omitempty"`
// Database additional user details (base64 encoded)
// +kubebuilder:validation:Required
Username string `json:"username"`

// Database additional user password (base64 encoded)
// +kubebuilder:validation:Required
Password string `json:"password"`

// New Database name
// +kubebuilder:validation:Required
Database string `json:"database"`

// Root user password
// +kubebuilder:validation:Required
Rootpwd string `json:"rootpwd"`

// Image name with version
// +kubebuilder:validation:Required
Image string `json:"image"`

// Database storage Path
// +kubebuilder:validation:Required
DataStoragePath string `json:"dataStoragePath"`

// Database storage Size (Ex. 1Gi, 100Mi)
// +optional
DataStorageSize string `json:"dataStorageSize"`

// Port number exposed for Database service
// +optional
// +kubebuilder:default=3306
// +kubebuilder:validation:Minimum=0
Port int32 `json:"port"`
}

type StatusPhase string

const (
RunningStatusPhase StatusPhase = "RUNNING"
BootstrapingStatusPhase StatusPhase = "BOOTSTRAP"
ErrorStatusPhase StatusPhase = "ERROR"
)

// MariaDBStatus defines the observed state of MariaDB
type MariaDBStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
CurrentReplicas *int32 `json:"currentReplicas,omitempty"` // If it's nil, it is unset, we'll use a default. If it is 0 than it is set to 0
DesiredReplicas int32 `json:"desiredReplicas"` // 0 is the same as unset (no value) and default will be applied even if user applies 0.
LastMessage string `json:"lastMessage"`
DbState StatusPhase `json:"dbState"`

}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:printcolumn:priority=0,name=MariaDB State,type=string,JSONPath=".status.dbState",description="State of the MariaDB instance",format=""
// +kubebuilder:printcolumn:priority=0,name=Port,type=string,JSONPath=".spec.port",description="Port of the MariaDB instance",format=""

// MariaDB is the Schema for the mariadbs API
type MariaDB struct {
Expand Down
68 changes: 64 additions & 4 deletions config/crd/bases/mariak8g.mariadb.org_mariadbs.yaml
Expand Up @@ -16,7 +16,16 @@ spec:
singular: mariadb
scope: Namespaced
versions:
- name: v1alpha1
- additionalPrinterColumns:
- description: State of the MariaDB instance
jsonPath: .status.dbState
name: MariaDB State
type: string
- description: Port of the MariaDB instance
jsonPath: .spec.port
name: Port
type: string
name: v1alpha1
schema:
openAPIV3Schema:
description: MariaDB is the Schema for the mariadbs API
Expand All @@ -36,13 +45,64 @@ spec:
spec:
description: MariaDBSpec defines the desired state of MariaDB
properties:
foo:
description: Foo is an example field of MariaDB. Edit mariadb_types.go
to remove/update
dataStoragePath:
description: Database storage Path
type: string
dataStorageSize:
description: Database storage Size (Ex. 1Gi, 100Mi)
type: string
database:
description: New Database name
type: string
image:
description: Image name with version
type: string
password:
description: Database additional user password (base64 encoded)
type: string
port:
default: 3306
description: Port number exposed for Database service
format: int32
minimum: 0
type: integer
rootpwd:
description: Root user password
type: string
size:
description: Size is the size of the deployment
format: int32
maximum: 4
minimum: 1
type: integer
username:
description: Database additional user details (base64 encoded)
type: string
required:
- dataStoragePath
- database
- image
- password
- rootpwd
- username
type: object
status:
description: MariaDBStatus defines the observed state of MariaDB
properties:
currentReplicas:
format: int32
type: integer
dbState:
type: string
desiredReplicas:
format: int32
type: integer
lastMessage:
type: string
required:
- dbState
- desiredReplicas
- lastMessage
type: object
type: object
served: true
Expand Down

0 comments on commit cd34e98

Please sign in to comment.