Skip to content

Commit

Permalink
feat(api): Extraction of public structures
Browse files Browse the repository at this point in the history
1. Extraction of public structures
    1. ingress
    2. service
    3. status
  • Loading branch information
wastill committed Dec 26, 2023
1 parent 765901b commit 29f9b03
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 14 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/sparkhistoryserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (sparkHistory *SparkHistoryServer) SetStatusCondition(condition metav1.Cond

// InitStatusConditions initializes the status conditions to the provided conditions.
func (sparkHistory *SparkHistoryServer) InitStatusConditions() {
sparkHistory.Status.InitStatus(sparkHistory)
sparkHistory.Status.InitStatusConditions()
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/onsi/ginkgo/v2 v2.13.0
github.com/onsi/gomega v1.29.0
github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684
github.com/zncdata-labs/operator-go v0.0.0-20231225134925-0f88208e24da
k8s.io/api v0.29.0
k8s.io/apimachinery v0.29.0
k8s.io/client-go v0.29.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684 h1:ZOb5wpkxbvdwfj8Sh4bu7MEAOpP7NlzouoRDRxwQMV0=
github.com/zncdata-labs/operator-go v0.0.0-20231222061826-114414d7e684/go.mod h1:y5EDDKn3tt5X9RiO+xsVAw26Xk65bdO1j3R0w1MA5d4=
github.com/zncdata-labs/operator-go v0.0.0-20231225134925-0f88208e24da h1:xWJEMqTlkTbhJ5WJ4xwO5/uRBry6okxjejAZqOTjIrs=
github.com/zncdata-labs/operator-go v0.0.0-20231225134925-0f88208e24da/go.mod h1:y5EDDKn3tt5X9RiO+xsVAw26Xk65bdO1j3R0w1MA5d4=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
Expand Down
1 change: 0 additions & 1 deletion internal/controller/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
zncdataerr "github.com/zncdata-labs/operator-go/pkg/errors"
"github.com/zncdata-labs/operator-go/pkg/status"
"github.com/zncdata-labs/operator-go/pkg/utils"

stackv1alpha1 "github.com/zncdata-labs/spark-k8s-operator/api/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
74 changes: 64 additions & 10 deletions internal/controller/sparkhistoryserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controller
import (
"context"
"github.com/go-logr/logr"
"github.com/zncdata-labs/operator-go/pkg/status"
"github.com/zncdata-labs/operator-go/pkg/utils"
stackv1alpha1 "github.com/zncdata-labs/spark-k8s-operator/api/v1alpha1"
apimeta "k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R

// Get the status condition, if it exists and its generation is not the
//same as the SparkHistoryServer's generation, reset the status conditions
readCondition := apimeta.FindStatusCondition(sparkHistory.Status.Conditions, stackv1alpha1.ConditionTypeProgressing)
readCondition := apimeta.FindStatusCondition(sparkHistory.Status.Conditions, status.ConditionTypeProgressing)
if readCondition == nil || readCondition.ObservedGeneration != sparkHistory.GetGeneration() {
sparkHistory.InitStatusConditions()

Expand All @@ -87,33 +88,86 @@ func (r *SparkHistoryServerReconciler) Reconcile(ctx context.Context, req ctrl.R
r.Log.Error(err, "unable to reconcile PVC")
return ctrl.Result{}, err
}
if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{
Type: status.ConditionTypeReconcilePVC,
Status: metav1.ConditionTrue,
Reason: status.ConditionReasonRunning,
Message: "SparkHistoryServer's PVC is running",
ObservedGeneration: sparkHistory.GetGeneration(),
}); updated {
if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil {
r.Log.Error(err, "unable to update status for PVC")
return ctrl.Result{}, err
}
}

if err := r.reconcileDeployment(ctx, sparkHistory); err != nil {
r.Log.Error(err, "unable to reconcile Deployment")
return ctrl.Result{}, err
}

if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{
Type: status.ConditionTypeReconcileDeployment,
Status: metav1.ConditionTrue,
Reason: status.ConditionReasonRunning,
Message: "SparkHistoryServer's deployment is running",
ObservedGeneration: sparkHistory.GetGeneration(),
}); updated {
if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil {
r.Log.Error(err, "unable to update status for Deployment")
return ctrl.Result{}, err
}
}

if err := r.reconcileService(ctx, sparkHistory); err != nil {
r.Log.Error(err, "unable to reconcile Service")
return ctrl.Result{}, err
}
if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{
Type: status.ConditionTypeReconcileService,
Status: metav1.ConditionTrue,
Reason: status.ConditionReasonRunning,
Message: "SparkHistoryServer's service is running",
ObservedGeneration: sparkHistory.GetGeneration(),
}); updated {
err := utils.UpdateStatus(ctx, r.Client, sparkHistory)
if err != nil {
r.Log.Error(err, "unable to update status for Service")
return ctrl.Result{}, err
}
}

if err := r.reconcileIngress(ctx, sparkHistory); err != nil {
r.Log.Error(err, "unable to reconcile Ingress")
return ctrl.Result{}, err
}

sparkHistory.SetStatusCondition(metav1.Condition{
Type: stackv1alpha1.ConditionTypeAvailable,
if updated := sparkHistory.Status.SetStatusCondition(metav1.Condition{
Type: status.ConditionTypeReconcileIngress,
Status: metav1.ConditionTrue,
Reason: stackv1alpha1.ConditionReasonRunning,
Message: "SparkHistoryServer is running",
Reason: status.ConditionReasonRunning,
Message: "SparkHistoryServer's ingress is running",
ObservedGeneration: sparkHistory.GetGeneration(),
})
}); updated {
err := utils.UpdateStatus(ctx, r.Client, sparkHistory)
if err != nil {
r.Log.Error(err, "unable to update status for Ingress")
return ctrl.Result{}, err
}
}

if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil {
r.Log.Error(err, "unable to update SparkHistoryServer status")
return ctrl.Result{}, err
if !sparkHistory.Status.IsAvailable() {
sparkHistory.SetStatusCondition(metav1.Condition{
Type: status.ConditionTypeAvailable,
Status: metav1.ConditionTrue,
Reason: status.ConditionReasonRunning,
Message: "SparkHistoryServer is running",
ObservedGeneration: sparkHistory.GetGeneration(),
})

if err := utils.UpdateStatus(ctx, r.Client, sparkHistory); err != nil {
r.Log.Error(err, "unable to update SparkHistoryServer status")
return ctrl.Result{}, err
}
}

r.Log.Info("Successfully reconciled SparkHistoryServer")
Expand Down

0 comments on commit 29f9b03

Please sign in to comment.