Browse Source

api update

iwanhae 1 year ago
parent
commit
cb2f550ccc
2 changed files with 25 additions and 8 deletions
  1. 18 7
      api/v1/postgresql_types.go
  2. 7 1
      internal/controller/postgresql_controller.go

+ 18 - 7
api/v1/postgresql_types.go

@@ -25,19 +25,30 @@ import (
 
 // PostgreSQLSpec defines the desired state of PostgreSQL
 type PostgreSQLSpec struct {
-	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
-	// Important: Run "make" to regenerate code after modifying this file
-
-	// Foo is an example field of PostgreSQL. Edit postgresql_types.go to remove/update
-	Foo string `json:"foo,omitempty"`
+	// Version of Postgres to deploy. [16.0]
+	Version string `json:"version"`
+	// Username for authentication
+	User string `json:"user"`
+	// Password for authentication
+	Password string `json:"password"`
+	// Autogenerated name for default DB
+	DB string `json:"database"`
 }
 
 // PostgreSQLStatus defines the observed state of PostgreSQL
 type PostgreSQLStatus struct {
-	// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
-	// Important: Run "make" to regenerate code after modifying this file
+	Status Status `json:"status"`
 }
 
+type Status string
+
+const (
+	Status_Pending      Status = "pending"
+	Status_Initializing Status = "initializing"
+	Status_Running      Status = "running"
+	Status_Error        Status = "error"
+)
+
 //+kubebuilder:object:root=true
 //+kubebuilder:subresource:status
 

+ 7 - 1
internal/controller/postgresql_controller.go

@@ -47,7 +47,13 @@ type PostgreSQLReconciler struct {
 // For more details, check Reconcile and its Result here:
 // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.16.0/pkg/reconcile
 func (r *PostgreSQLReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
-	_ = log.FromContext(ctx)
+	logger := log.FromContext(ctx)
+
+	obj := databasev1.PostgreSQL{}
+	if err := r.Get(ctx, req.NamespacedName, &obj); err != nil {
+		logger.Error(err, "resource not found")
+		return ctrl.Result{}, err
+	}
 
 	// TODO(user): your logic here