-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
993 additions
and
4 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
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,68 @@ | ||
package cluster | ||
|
||
import ( | ||
"context" | ||
|
||
supersetv1alpha1 "github.com/zncdata-labs/superset-operator/api/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/internal/controller/node" | ||
"github.com/zncdata-labs/superset-operator/internal/controller/worker" | ||
apiv1alpha1 "github.com/zncdata-labs/superset-operator/pkg/apis/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/pkg/image" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
) | ||
|
||
type Reconciler struct { | ||
reconciler.BaseClusterReconciler[*supersetv1alpha1.SupersetClusterSpec] | ||
ClusterOperation *apiv1alpha1.ClusterOperationSpec | ||
ClusterConfig *supersetv1alpha1.ClusterConfigSpec | ||
Image image.Image | ||
} | ||
|
||
func (r *Reconciler) RegisterResources(_ context.Context) error { | ||
|
||
node := node.NewReconciler( | ||
r.Client, | ||
r.ClusterConfig, | ||
r.ClusterOperation, | ||
r.Image, | ||
"node", | ||
r.Spec.Node, | ||
) | ||
r.AddResource(node) | ||
|
||
worker := worker.NewReconciler( | ||
r.Client, | ||
r.ClusterConfig, | ||
r.ClusterOperation, | ||
r.Image, | ||
"worker", | ||
r.Spec.Worker, | ||
) | ||
r.AddResource(worker) | ||
|
||
return nil | ||
} | ||
|
||
func NewReconciler( | ||
client reconciler.ResourceClient, | ||
cluster *supersetv1alpha1.SupersetCluster, | ||
) *Reconciler { | ||
|
||
image := image.Image{ | ||
Repo: cluster.Spec.Image.Repo, | ||
Custom: cluster.Spec.Image.Custom, | ||
KDSVersion: cluster.Spec.Image.KDSVersion, | ||
ProductVersion: cluster.Spec.Image.ProductVersion, | ||
} | ||
|
||
return &Reconciler{ | ||
BaseClusterReconciler: *reconciler.NewBaseClusterReconciler( | ||
client, | ||
client.GetOwnerName(), | ||
&cluster.Spec, | ||
), | ||
ClusterOperation: cluster.Spec.ClusterOperation, | ||
ClusterConfig: cluster.Spec.ClusterConfig, | ||
Image: image, | ||
} | ||
} |
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,37 @@ | ||
package cluster | ||
|
||
import ( | ||
supersetv1alpha1 "github.com/zncdata-labs/superset-operator/api/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/pkg/image" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
batchv1 "k8s.io/api/batch/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type JobReconciler struct { | ||
reconciler.BaseResourceReconciler[*supersetv1alpha1.SupersetClusterSpec] | ||
Image image.Image | ||
} | ||
|
||
func (r *JobReconciler) Build() (*batchv1.Job, error) { | ||
obj := &batchv1.Job{ | ||
ObjectMeta: r.GetObjectMeta(), | ||
Spec: batchv1.JobSpec{ | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: r.Client.GetLabels(), | ||
}, | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: r.GetName(), | ||
Image: r.Image.Custom, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
return obj, nil | ||
} |
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,37 @@ | ||
package node | ||
|
||
import ( | ||
supersetv1alpha1 "github.com/zncdata-labs/superset-operator/api/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/pkg/image" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type DeploymentReconciler struct { | ||
reconciler.DeploymentReconciler[*supersetv1alpha1.NodeRoleGroupSpec] | ||
ClusterConfig *supersetv1alpha1.ClusterConfigSpec | ||
} | ||
|
||
func NewDeploymentReconciler( | ||
client reconciler.ResourceClient, | ||
|
||
name string, | ||
|
||
clusterConfig *supersetv1alpha1.ClusterConfigSpec, | ||
image image.Image, | ||
ports []corev1.ContainerPort, | ||
|
||
spec *supersetv1alpha1.NodeRoleGroupSpec, | ||
) *DeploymentReconciler { | ||
|
||
return &DeploymentReconciler{ | ||
DeploymentReconciler: *reconciler.NewDeploymentReconciler( | ||
client, | ||
name, | ||
image, | ||
ports, | ||
spec, | ||
), | ||
ClusterConfig: clusterConfig, | ||
} | ||
} |
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,31 @@ | ||
package node | ||
|
||
import ( | ||
supersetv1alpha1 "github.com/zncdata-labs/superset-operator/api/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
corev1 "k8s.io/api/core/v1" | ||
networkv1 "k8s.io/api/networking/v1" | ||
) | ||
|
||
type IngressReconciler struct { | ||
reconciler.BaseResourceReconciler[*supersetv1alpha1.NodeRoleGroupSpec] | ||
Ports []corev1.ContainerPort | ||
} | ||
|
||
func (r *IngressReconciler) Build() (*networkv1.Ingress, error) { | ||
panic("unimplemented") | ||
} | ||
|
||
func NewIngressReconciler( | ||
client reconciler.ResourceClient, | ||
roleGroupName string, | ||
spec *supersetv1alpha1.NodeRoleGroupSpec, | ||
) *IngressReconciler { | ||
return &IngressReconciler{ | ||
BaseResourceReconciler: *reconciler.NewBaseResourceReconciler( | ||
client, | ||
roleGroupName, | ||
spec, | ||
), | ||
} | ||
} |
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,12 @@ | ||
package node | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
var ( | ||
Ports = []corev1.ContainerPort{ | ||
{ | ||
Name: "http", | ||
ContainerPort: 8088, | ||
}, | ||
} | ||
) |
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,78 @@ | ||
package node | ||
|
||
import ( | ||
"context" | ||
|
||
supersetv1alpha1 "github.com/zncdata-labs/superset-operator/api/v1alpha1" | ||
apiv1alpha1 "github.com/zncdata-labs/superset-operator/pkg/apis/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/pkg/image" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
) | ||
|
||
var _ reconciler.RoleReconciler = &Reconciler{} | ||
|
||
type Reconciler struct { | ||
reconciler.BaseRoleReconciler[*supersetv1alpha1.NodeSpec] | ||
ClusterConfig *supersetv1alpha1.ClusterConfigSpec | ||
} | ||
|
||
func (r *Reconciler) RegisterResources(ctx context.Context) error { | ||
for name, rg := range r.Spec.RoleGroups { | ||
mergedRoleGroup := rg.DeepCopy() | ||
r.MergeRoleGroup(&mergedRoleGroup) | ||
|
||
if err := r.RegisterResourceWithRoleGroup(ctx, name, mergedRoleGroup); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (r *Reconciler) RegisterResourceWithRoleGroup( | ||
_ context.Context, | ||
name string, | ||
roleGroup *supersetv1alpha1.NodeRoleGroupSpec, | ||
) error { | ||
|
||
deployment := NewDeploymentReconciler( | ||
r.Client, | ||
name, | ||
r.ClusterConfig, | ||
r.Image, | ||
Ports, | ||
roleGroup, | ||
) | ||
r.AddResource(deployment) | ||
|
||
service := NewServiceReconciler( | ||
r.Client, | ||
name, | ||
Ports, | ||
roleGroup, | ||
) | ||
r.AddResource(service) | ||
|
||
return nil | ||
} | ||
|
||
func NewReconciler( | ||
client reconciler.ResourceClient, | ||
clusterConfig *supersetv1alpha1.ClusterConfigSpec, | ||
clusterOperation *apiv1alpha1.ClusterOperationSpec, | ||
imageSpec image.Image, | ||
name string, | ||
spec *supersetv1alpha1.NodeSpec, | ||
|
||
) *Reconciler { | ||
|
||
return &Reconciler{ | ||
BaseRoleReconciler: *reconciler.NewBaseRoleReconciler( | ||
client, | ||
name, | ||
clusterOperation, | ||
imageSpec, | ||
spec, | ||
), | ||
ClusterConfig: clusterConfig, | ||
} | ||
} |
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,53 @@ | ||
package node | ||
|
||
import ( | ||
"context" | ||
|
||
supersetv1alpha1 "github.com/zncdata-labs/superset-operator/api/v1alpha1" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type ServiceReconciler struct { | ||
reconciler.BaseResourceReconciler[*supersetv1alpha1.NodeRoleGroupSpec] | ||
Ports []corev1.ContainerPort | ||
} | ||
|
||
func (r *ServiceReconciler) Build(_ context.Context) (*corev1.Service, error) { | ||
var ports []corev1.ServicePort | ||
|
||
for _, port := range r.Ports { | ||
ports = append(ports, corev1.ServicePort{ | ||
Name: port.Name, | ||
Port: port.ContainerPort, | ||
Protocol: port.Protocol, | ||
}) | ||
} | ||
|
||
obj := &corev1.Service{ | ||
ObjectMeta: r.GetObjectMeta(), | ||
Spec: corev1.ServiceSpec{ | ||
Selector: map[string]string{ | ||
"app": r.GetName(), | ||
}, | ||
Ports: ports, | ||
}, | ||
} | ||
return obj, nil | ||
} | ||
|
||
func NewServiceReconciler( | ||
client reconciler.ResourceClient, | ||
roleGroupName string, | ||
ports []corev1.ContainerPort, | ||
spec *supersetv1alpha1.NodeRoleGroupSpec, | ||
) *ServiceReconciler { | ||
return &ServiceReconciler{ | ||
BaseResourceReconciler: *reconciler.NewBaseResourceReconciler( | ||
client, | ||
roleGroupName, | ||
spec, | ||
), | ||
Ports: ports, | ||
} | ||
} |
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 |
---|---|---|
|
@@ -19,6 +19,8 @@ package controller | |
import ( | ||
"context" | ||
|
||
"github.com/zncdata-labs/superset-operator/internal/controller/cluster" | ||
"github.com/zncdata-labs/superset-operator/pkg/reconciler" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
@@ -32,13 +34,50 @@ type SupersetClusterReconciler struct { | |
Scheme *runtime.Scheme | ||
} | ||
|
||
//+kubebuilder:rbac:groups=superset.zncdata.dev,resources=supersetclusters,verbs=get;list;watch;create;update;patch;delete | ||
//+kubebuilder:rbac:groups=superset.zncdata.dev,resources=supersetclusters/status,verbs=get;update;patch | ||
//+kubebuilder:rbac:groups=superset.zncdata.dev,resources=supersetclusters/finalizers,verbs=update | ||
var ( | ||
logger = ctrl.Log.WithName("common").WithName("reconciler") | ||
) | ||
|
||
// +kubebuilder:rbac:groups=superset.zncdata.dev,resources=supersetclusters,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=superset.zncdata.dev,resources=supersetclusters/status,verbs=get;update;patch | ||
// +kubebuilder:rbac:groups=superset.zncdata.dev,resources=supersetclusters/finalizers,verbs=update | ||
|
||
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *SupersetClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
|
||
logger.V(0).Info("Reconciling SupersetCluster") | ||
|
||
instance := &supersetv1alpha1.SupersetCluster{} | ||
err := r.Get(ctx, req.NamespacedName, instance) | ||
if err != nil { | ||
if client.IgnoreNotFound(err) == nil { | ||
logger.V(1).Info("SupersetCluster resource not found. Ignoring since object must be deleted.") | ||
return ctrl.Result{}, nil | ||
} | ||
return ctrl.Result{}, err | ||
} | ||
|
||
resourceClient := reconciler.ResourceClient{ | ||
Client: r.Client, | ||
} | ||
|
||
clusterRreconciler := cluster.NewReconciler(resourceClient, instance) | ||
|
||
if err := clusterRreconciler.RegisterResources(ctx); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
if result := clusterRreconciler.Reconcile(); result.RequeueOrNot() { | ||
return result.Result() | ||
} | ||
|
||
if result := clusterRreconciler.Ready(); result.RequeueOrNot() { | ||
return result.Result() | ||
} | ||
|
||
logger.V(0).Info("Reconcile completed") | ||
|
||
return ctrl.Result{}, nil | ||
} | ||
|
||
|
Oops, something went wrong.