-
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 status checks…
feat: add options struct and prune client (#20)
Showing
35 changed files
with
1,201 additions
and
836 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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package v1alpha1 | ||
|
||
type ImageSpec struct { | ||
Custom string `json:"custom,omitempty"` | ||
Repo string `json:"repo,omitempty"` | ||
KDSVersion string `json:"kdsVersion,omitempty"` | ||
// +kubebuilder:validation:Optional | ||
Custom string `json:"custom,omitempty"` | ||
// +kubebuilder:validation:Optional | ||
Repo string `json:"repo,omitempty"` | ||
// +kubebuilder:validation:Optional | ||
KDSVersion string `json:"kdsVersion,omitempty"` | ||
// +kubebuilder:validation:Optional | ||
ProductVersion string `json:"productVersion,omitempty"` | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -1,33 +1,26 @@ | ||
package node | ||
|
||
import ( | ||
supersetv1alpha1 "github.com/zncdatadev/superset-operator/api/v1alpha1" | ||
"github.com/zncdatadev/superset-operator/internal/controller/common" | ||
resourceClient "github.com/zncdatadev/superset-operator/pkg/client" | ||
"github.com/zncdatadev/superset-operator/pkg/builder" | ||
"github.com/zncdatadev/superset-operator/pkg/client" | ||
"github.com/zncdatadev/superset-operator/pkg/reconciler" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func NewDeploymentReconciler( | ||
client resourceClient.ResourceClient, | ||
client *client.Client, | ||
clusterConfig *common.ClusterConfig, | ||
roleGroupInfo *reconciler.RoleGroupInfo, | ||
ports []corev1.ContainerPort, | ||
spec *supersetv1alpha1.NodeRoleGroupSpec, | ||
options *builder.RoleGroupOptions, | ||
) *reconciler.DeploymentReconciler { | ||
deploymentBuilder := common.NewDeploymentBuilder( | ||
client, | ||
clusterConfig, | ||
roleGroupInfo, | ||
ports, | ||
spec.EnvOverrides, | ||
spec.CommandOverrides, | ||
options, | ||
) | ||
|
||
return reconciler.NewDeploymentReconciler( | ||
client, | ||
roleGroupInfo, | ||
ports, | ||
options, | ||
deploymentBuilder, | ||
) | ||
} |
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
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
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,149 +1,154 @@ | ||
package builder | ||
|
||
import ( | ||
resourceClient "github.com/zncdatadev/superset-operator/pkg/client" | ||
"context" | ||
|
||
client "github.com/zncdatadev/superset-operator/pkg/client" | ||
"github.com/zncdatadev/superset-operator/pkg/util" | ||
appv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
var ( | ||
DefaultReplicas = int32(1) | ||
) | ||
|
||
type DeploymentBuilder interface { | ||
Builder | ||
|
||
GetObject() *appv1.Deployment | ||
SetReplicas(replicas *int32) DeploymentBuilder | ||
SetReplicas(replicas *int32) | ||
|
||
AddContainer(*corev1.Container) DeploymentBuilder | ||
AddContainers([]corev1.Container) DeploymentBuilder | ||
ResetContainers(containers []corev1.Container) DeploymentBuilder | ||
AddContainer(*corev1.Container) | ||
AddContainers([]corev1.Container) | ||
ResetContainers(containers []corev1.Container) | ||
|
||
AddInitContainer(*corev1.Container) DeploymentBuilder | ||
AddInitContainers([]corev1.Container) DeploymentBuilder | ||
ResetInitContainers(containers []corev1.Container) DeploymentBuilder | ||
AddInitContainer(*corev1.Container) | ||
AddInitContainers([]corev1.Container) | ||
ResetInitContainers(containers []corev1.Container) | ||
|
||
AddVolume(*corev1.Volume) DeploymentBuilder | ||
AddVolumes([]corev1.Volume) DeploymentBuilder | ||
ResetVolumes(volumes []corev1.Volume) DeploymentBuilder | ||
AddVolume(*corev1.Volume) | ||
AddVolumes([]corev1.Volume) | ||
ResetVolumes(volumes []corev1.Volume) | ||
|
||
AddTerminationGracePeriodSeconds(seconds *int64) DeploymentBuilder | ||
AddAffinity(*corev1.Affinity) DeploymentBuilder | ||
AddTerminationGracePeriodSeconds(seconds *int64) | ||
AddAffinity(*corev1.Affinity) | ||
} | ||
|
||
var _ DeploymentBuilder = &GenericDeploymentBuilder{} | ||
|
||
type GenericDeploymentBuilder struct { | ||
BaseResourceBuilder | ||
EnvOverrides map[string]string | ||
CommandOverrides []string | ||
Image util.Image | ||
Options *RoleGroupOptions | ||
|
||
obj *appv1.Deployment | ||
replicas *int32 | ||
initContainers []corev1.Container | ||
containers []corev1.Container | ||
volumes []corev1.Volume | ||
terminationGracePeriodSeconds *int64 | ||
affinity *corev1.Affinity | ||
} | ||
|
||
func NewGenericDeploymentBuilder( | ||
client resourceClient.ResourceClient, | ||
name string, | ||
envOverrides map[string]string, | ||
commandOverrides []string, | ||
image util.Image, | ||
client *client.Client, | ||
options *RoleGroupOptions, | ||
) *GenericDeploymentBuilder { | ||
return &GenericDeploymentBuilder{ | ||
BaseResourceBuilder: BaseResourceBuilder{ | ||
Client: client, | ||
Name: name, | ||
Client: client, | ||
Options: options, | ||
}, | ||
EnvOverrides: envOverrides, | ||
CommandOverrides: commandOverrides, | ||
Image: image, | ||
Options: options, | ||
} | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) GetObject() *appv1.Deployment { | ||
if b.obj == nil { | ||
b.obj = &appv1.Deployment{ | ||
ObjectMeta: b.GetObjectMeta(), | ||
Spec: appv1.DeploymentSpec{ | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: b.Client.GetLabels(), | ||
if b.replicas == nil { | ||
b.replicas = &DefaultReplicas | ||
} | ||
obj := &appv1.Deployment{ | ||
Spec: appv1.DeploymentSpec{ | ||
Replicas: b.replicas, | ||
Selector: &metav1.LabelSelector{ | ||
MatchLabels: b.Options.GetMatchingLabels(), | ||
}, | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: b.Options.GetLabels(), | ||
Annotations: b.Options.GetAnnotations(), | ||
}, | ||
Template: corev1.PodTemplateSpec{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: b.Client.GetLabels(), | ||
Annotations: b.Client.GetAnnotations(), | ||
}, | ||
Spec: corev1.PodSpec{ | ||
InitContainers: b.initContainers, | ||
Containers: b.containers, | ||
Volumes: b.volumes, | ||
Affinity: b.affinity, | ||
TerminationGracePeriodSeconds: b.terminationGracePeriodSeconds, | ||
}, | ||
}, | ||
} | ||
}, | ||
} | ||
return b.obj | ||
return obj | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) SetReplicas(replicas *int32) DeploymentBuilder { | ||
b.GetObject().Spec.Replicas = replicas | ||
return b | ||
func (b *GenericDeploymentBuilder) SetReplicas(replicas *int32) { | ||
b.replicas = replicas | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) AddContainer(container *corev1.Container) DeploymentBuilder { | ||
c := b.GetObject().Spec.Template.Spec.Containers | ||
c = append(c, *container) | ||
b.GetObject().Spec.Template.Spec.Containers = c | ||
return b | ||
func (b *GenericDeploymentBuilder) AddContainer(container *corev1.Container) { | ||
b.containers = append(b.containers, *container) | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) AddContainers(containers []corev1.Container) DeploymentBuilder { | ||
c := b.GetObject().Spec.Template.Spec.Containers | ||
c = append(c, containers...) | ||
b.GetObject().Spec.Template.Spec.Containers = c | ||
return b | ||
func (b *GenericDeploymentBuilder) AddContainers(containers []corev1.Container) { | ||
b.containers = append(b.containers, containers...) | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) ResetContainers(containers []corev1.Container) DeploymentBuilder { | ||
b.GetObject().Spec.Template.Spec.Containers = containers | ||
return b | ||
func (b *GenericDeploymentBuilder) ResetContainers(containers []corev1.Container) { | ||
b.containers = containers | ||
} | ||
func (b *GenericDeploymentBuilder) AddInitContainers(containers []corev1.Container) DeploymentBuilder { | ||
c := b.GetObject().Spec.Template.Spec.InitContainers | ||
c = append(c, containers...) | ||
b.GetObject().Spec.Template.Spec.InitContainers = c | ||
return b | ||
func (b *GenericDeploymentBuilder) AddInitContainers(containers []corev1.Container) { | ||
b.initContainers = append(b.initContainers, containers...) | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) ResetInitContainers(containers []corev1.Container) DeploymentBuilder { | ||
b.GetObject().Spec.Template.Spec.InitContainers = containers | ||
return b | ||
func (b *GenericDeploymentBuilder) AddInitContainer(container *corev1.Container) { | ||
b.initContainers = append(b.initContainers, *container) | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) AddInitContainer(container *corev1.Container) DeploymentBuilder { | ||
c := b.GetObject().Spec.Template.Spec.InitContainers | ||
c = append(c, *container) | ||
b.GetObject().Spec.Template.Spec.InitContainers = c | ||
return b | ||
func (b *GenericDeploymentBuilder) ResetInitContainers(containers []corev1.Container) { | ||
b.initContainers = containers | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) AddVolume(volume *corev1.Volume) DeploymentBuilder { | ||
v := b.GetObject().Spec.Template.Spec.Volumes | ||
v = append(v, *volume) | ||
b.GetObject().Spec.Template.Spec.Volumes = v | ||
return b | ||
func (b *GenericDeploymentBuilder) AddVolume(volume *corev1.Volume) { | ||
b.volumes = append(b.volumes, *volume) | ||
} | ||
func (b *GenericDeploymentBuilder) AddVolumes(volumes []corev1.Volume) { | ||
b.volumes = append(b.volumes, volumes...) | ||
} | ||
func (b *GenericDeploymentBuilder) AddVolumes(volumes []corev1.Volume) DeploymentBuilder { | ||
v := b.GetObject().Spec.Template.Spec.Volumes | ||
v = append(v, volumes...) | ||
b.GetObject().Spec.Template.Spec.Volumes = v | ||
return b | ||
|
||
func (b *GenericDeploymentBuilder) ResetVolumes(volumes []corev1.Volume) { | ||
b.volumes = volumes | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) ResetVolumes(volumes []corev1.Volume) DeploymentBuilder { | ||
b.GetObject().Spec.Template.Spec.Volumes = volumes | ||
return b | ||
func (b *GenericDeploymentBuilder) AddTerminationGracePeriodSeconds(seconds *int64) { | ||
b.terminationGracePeriodSeconds = seconds | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) AddTerminationGracePeriodSeconds(seconds *int64) DeploymentBuilder { | ||
b.GetObject().Spec.Template.Spec.TerminationGracePeriodSeconds = seconds | ||
return b | ||
func (b *GenericDeploymentBuilder) AddAffinity(affinity *corev1.Affinity) { | ||
b.affinity = affinity | ||
} | ||
|
||
func (b *GenericDeploymentBuilder) AddAffinity(affinity *corev1.Affinity) DeploymentBuilder { | ||
b.GetObject().Spec.Template.Spec.Affinity = affinity | ||
return b | ||
func (b *GenericDeploymentBuilder) Build(_ context.Context) (ctrlclient.Object, error) { | ||
obj := b.GetObject() | ||
|
||
if b.containers == nil { | ||
obj.Spec.Template.Spec.Containers = []corev1.Container{ | ||
{ | ||
Name: b.Options.Name, | ||
Image: b.Options.GetImage().String(), | ||
Env: util.EnvsToEnvVars(b.Options.EnvOverrides), | ||
Command: b.Options.CommandOverrides, | ||
}, | ||
} | ||
} | ||
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
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,148 @@ | ||
package builder | ||
|
||
import ( | ||
apiv1alpha1 "github.com/zncdatadev/superset-operator/pkg/apis/v1alpha1" | ||
"github.com/zncdatadev/superset-operator/pkg/util" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var ( | ||
MatchingLabelsNames = []string{ | ||
"app.kubernetes.io/name", | ||
"app.kubernetes.io/instance", | ||
"app.kubernetes.io/role-group", | ||
"app.kubernetes.io/component", | ||
} | ||
) | ||
|
||
type Options interface { | ||
GetName() string | ||
GetFullName() string | ||
GetLabels() map[string]string | ||
AddLabels(labels map[string]string) | ||
GetMatchingLabels() map[string]string | ||
GetAnnotations() map[string]string | ||
|
||
GetClusterOperation() *apiv1alpha1.ClusterOperationSpec | ||
GetImage() *util.Image | ||
GetPorts() []corev1.ContainerPort | ||
SetPorts(ports []corev1.ContainerPort) | ||
} | ||
|
||
var _ Options = &ClusterOptions{} | ||
|
||
type ClusterOptions struct { | ||
Name string | ||
Namespace string | ||
Labels map[string]string | ||
Annotations map[string]string | ||
ClusterOperation *apiv1alpha1.ClusterOperationSpec | ||
Image *util.Image | ||
Ports []corev1.ContainerPort | ||
} | ||
|
||
func (o *ClusterOptions) GetName() string { | ||
return o.Name | ||
} | ||
|
||
func (o *ClusterOptions) GetFullName() string { | ||
return o.Name | ||
} | ||
|
||
func (o *ClusterOptions) GetLabels() map[string]string { | ||
return o.Labels | ||
} | ||
|
||
func (o *ClusterOptions) GetAnnotations() map[string]string { | ||
return o.Annotations | ||
} | ||
|
||
func (o *ClusterOptions) AddLabels(labels map[string]string) { | ||
for k, v := range labels { | ||
o.Labels[k] = v | ||
} | ||
} | ||
|
||
func (o *ClusterOptions) filterLabels(labels map[string]string) map[string]string { | ||
|
||
matchingLabels := make(map[string]string) | ||
for _, label := range MatchingLabelsNames { | ||
if value, ok := labels[label]; ok { | ||
matchingLabels[label] = value | ||
} | ||
} | ||
return matchingLabels | ||
} | ||
|
||
func (o *ClusterOptions) GetMatchingLabels() map[string]string { | ||
return o.filterLabels(o.GetLabels()) | ||
} | ||
|
||
func (o *ClusterOptions) GetClusterOperation() *apiv1alpha1.ClusterOperationSpec { | ||
return o.ClusterOperation | ||
} | ||
|
||
func (o *ClusterOptions) GetImage() *util.Image { | ||
return o.Image | ||
} | ||
|
||
func (o *ClusterOptions) GetPorts() []corev1.ContainerPort { | ||
return o.Ports | ||
} | ||
|
||
func (o *ClusterOptions) SetPorts(ports []corev1.ContainerPort) { | ||
o.Ports = ports | ||
} | ||
|
||
type RoleOptions struct { | ||
ClusterOptions | ||
Name string | ||
} | ||
|
||
func (o *RoleOptions) GetName() string { | ||
return o.Name | ||
} | ||
|
||
func (o *RoleOptions) GetFullName() string { | ||
return o.ClusterOptions.Name + "-" + o.Name | ||
} | ||
|
||
func (o *RoleOptions) GetLabels() map[string]string { | ||
labels := o.ClusterOptions.Labels | ||
labels["app.kubernetes.io/component"] = o.Name | ||
return labels | ||
} | ||
|
||
func (o *RoleOptions) GetMatchingLabels() map[string]string { | ||
return o.filterLabels(o.GetLabels()) | ||
} | ||
|
||
type RoleGroupOptions struct { | ||
RoleOptions | ||
Name string | ||
Replicas *int32 | ||
|
||
PodDisruptionBudget *apiv1alpha1.PodDisruptionBudgetSpec | ||
|
||
CommandOverrides []string | ||
EnvOverrides map[string]string | ||
PodOverrides *corev1.PodTemplateSpec | ||
} | ||
|
||
func (o *RoleGroupOptions) GetName() string { | ||
return o.Name | ||
} | ||
|
||
func (o *RoleGroupOptions) GetFullName() string { | ||
return o.RoleOptions.GetFullName() + "-" + o.Name | ||
} | ||
|
||
func (o *RoleGroupOptions) GetLabels() map[string]string { | ||
labels := o.RoleOptions.GetLabels() | ||
labels["app.kubernetes.io/role-group"] = o.Name | ||
return labels | ||
} | ||
|
||
func (o *RoleGroupOptions) GetMatchingLabels() map[string]string { | ||
return o.filterLabels(o.GetLabels()) | ||
} |
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
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
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
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
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
Oops, something went wrong.