Skip to content

Commit

Permalink
Fix bugs (#319)
Browse files Browse the repository at this point in the history
* fix arm arch

* fix bugs
  • Loading branch information
MegaByte875 authored Oct 9, 2023
1 parent 55f4dc9 commit 51761f6
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Dockerfile.multiarch
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM --platform=$BUILDPLATFORM alpine:3.18.2
FROM alpine:3.18.2

ARG BUILDPLATFORM
ARG TARGETPLATFORM

RUN addgroup -S -g 65532 ng-user && \
adduser -S -D -H -u 65532 \
-s /sbin/nologin -G ng-user -g ng-user ng-user

ADD bin/${BUILDPLATFORM}/controller-manager /usr/local/bin/controller-manager
ADD bin/${BUILDPLATFORM}/autoscaler /usr/local/bin/autoscaler
ADD bin/${BUILDPLATFORM}/scheduler /usr/local/bin/scheduler
ADD bin/${TARGETPLATFORM}/controller-manager /usr/local/bin/controller-manager
ADD bin/${TARGETPLATFORM}/autoscaler /usr/local/bin/autoscaler
ADD bin/${TARGETPLATFORM}/scheduler /usr/local/bin/scheduler
USER 65532:65532
4 changes: 3 additions & 1 deletion alpine.multiarch
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM --platform=$BUILDPLATFORM alpine:3.18.2
FROM alpine:3.18.2

ARG TARGETPLATFORM

RUN apk update \
&& apk upgrade \
Expand Down
7 changes: 7 additions & 0 deletions apis/apps/v1alpha1/nebulacluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ func getClientCertsVolume(sslCerts *SSLCertsSpec) []corev1.Volume {
}
}

func rollingUpdateDone(workloadStatus WorkloadStatus) bool {
return workloadStatus.UpdatedReplicas == workloadStatus.Replicas &&
workloadStatus.ReadyReplicas == workloadStatus.Replicas &&
workloadStatus.CurrentReplicas == workloadStatus.UpdatedReplicas &&
workloadStatus.CurrentRevision == workloadStatus.UpdateRevision
}

func upgradeStatefulSet(sts *appsv1.StatefulSet) (*kruisev1alpha1.StatefulSet, error) {
data, err := json.Marshal(sts)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_graphd.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ func (c *graphdComponent) GetEndpoints(portName string) []string {
}

func (c *graphdComponent) IsReady() bool {
return *c.nc.Spec.Graphd.Replicas == c.nc.Status.Graphd.Workload.ReadyReplicas
return *c.nc.Spec.Graphd.Replicas == c.nc.Status.Graphd.Workload.ReadyReplicas &&
rollingUpdateDone(c.nc.Status.Graphd.Workload)
}

func (c *graphdComponent) GenerateLabels() map[string]string {
Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_metad.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func (c *metadComponent) GetEndpoints(portName string) []string {
}

func (c *metadComponent) IsReady() bool {
return *c.nc.Spec.Metad.Replicas == c.nc.Status.Metad.Workload.ReadyReplicas
return *c.nc.Spec.Metad.Replicas == c.nc.Status.Metad.Workload.ReadyReplicas &&
rollingUpdateDone(c.nc.Status.Metad.Workload)
}

func (c *metadComponent) GenerateLabels() map[string]string {
Expand Down
3 changes: 2 additions & 1 deletion apis/apps/v1alpha1/nebulacluster_storaged.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func (c *storagedComponent) GetEndpoints(portName string) []string {
}

func (c *storagedComponent) IsReady() bool {
return *c.nc.Spec.Storaged.Replicas == c.nc.Status.Storaged.Workload.ReadyReplicas
return *c.nc.Spec.Storaged.Replicas == c.nc.Status.Storaged.Workload.ReadyReplicas &&
rollingUpdateDone(c.nc.Status.Storaged.Workload)
}

func (c *storagedComponent) GenerateLabels() map[string]string {
Expand Down
7 changes: 4 additions & 3 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type NebulaClusterSpec struct {
Affinity *corev1.Affinity `json:"affinity,omitempty"`

// +optional
Tolerations []corev1.Toleration `json:"toleration,omitempty"`
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`

// Flag to enable/disable sidecar container nebula-agent injection, default false.
// +optional
Expand Down Expand Up @@ -153,11 +153,11 @@ type WorkloadStatus struct {
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// The number of ready replicas.
// ReadyReplicas is the number of pods with a Ready Condition.
// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`

// Replicas is the most recently observed number of replicas.
// Replicas is the number of pods created by the Workload controller.
Replicas int32 `json:"replicas"`

// The number of pods in updatedRevision.
Expand Down Expand Up @@ -554,6 +554,7 @@ type ServiceSpec struct {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=nc
// +kubebuilder:printcolumn:name="READY",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
// +kubebuilder:printcolumn:name="GRAPHD-DESIRED",type="string",JSONPath=".spec.graphd.replicas",description="The desired number of graphd pods."
// +kubebuilder:printcolumn:name="GRAPHD-READY",type="string",JSONPath=".status.graphd.workload.readyReplicas",description="The number of graphd pods ready."
// +kubebuilder:printcolumn:name="METAD-DESIRED",type="string",JSONPath=".spec.metad.replicas",description="The desired number of metad pods."
Expand Down
7 changes: 0 additions & 7 deletions apis/apps/v1alpha1/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,9 @@ var DynamicFlags = map[string]string{
"wal_ttl": "14400",
"query_concurrently": "true",
"auto_remove_invalid_space": "true",
"num_io_threads": "16",
"num_worker_threads": "0",
"max_concurrent_subtasks": "10",
"snapshot_part_rate_limit": "10485760",
"snapshot_batch_size": "1048576",
"rebuild_index_part_rate_limit": "4194304",
"rocksdb_db_options": "{}",
"rocksdb_column_family_options": `{"write_buffer_size":"67108864","max_write_buffer_number":"4","max_bytes_for_level_base":"268435456"}`,
"rocksdb_block_based_table_options": `{"block_size":"8192"}`,
"prioritize_intra_zone_reading": "false",
"stick_to_intra_zone_on_failure": "false",
"sync_meta_when_use_space": "false",
"validate_session_timestamp": "true",
Expand Down
5 changes: 4 additions & 1 deletion charts/nebula-operator/crds/nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: READY
type: string
- description: The desired number of graphd pods.
jsonPath: .spec.graphd.replicas
name: GRAPHD-DESIRED
Expand Down Expand Up @@ -11599,7 +11602,7 @@ spec:
type: object
suspend:
type: boolean
toleration:
tolerations:
items:
properties:
effect:
Expand Down
5 changes: 4 additions & 1 deletion config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .status.conditions[?(@.type=="Ready")].status
name: READY
type: string
- description: The desired number of graphd pods.
jsonPath: .spec.graphd.replicas
name: GRAPHD-DESIRED
Expand Down Expand Up @@ -11599,7 +11602,7 @@ spec:
type: object
suspend:
type: boolean
toleration:
tolerations:
items:
properties:
effect:
Expand Down
15 changes: 15 additions & 0 deletions pkg/controller/autoscaler/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ type NormalizationArg struct {
// 4. Apply the stabilization (i.e. add no more than 4 pods per minute, and pick the smallest recommendation during last 5 minutes)
func (a *HorizontalController) normalizeDesiredReplicasWithBehaviors(hpa *v1alpha1.NebulaAutoscaler, key string, currentReplicas, prenormalizedDesiredReplicas, minReplicas int32) int32 {
a.maybeInitScaleDownStabilizationWindow(hpa)
a.maybeInitSelectPolicy(hpa)
normalizationArg := NormalizationArg{
Key: key,
ScaleUpBehavior: hpa.Spec.GraphdPolicy.Behavior.ScaleUp,
Expand Down Expand Up @@ -626,6 +627,20 @@ func (a *HorizontalController) maybeInitScaleDownStabilizationWindow(hpa *v1alph
}
}

func (a *HorizontalController) maybeInitSelectPolicy(hpa *v1alpha1.NebulaAutoscaler) {
behavior := hpa.Spec.GraphdPolicy.Behavior
if behavior != nil {
if behavior.ScaleUp != nil && behavior.ScaleUp.SelectPolicy == nil {
selectPolicy := autoscalingv2.MaxChangePolicySelect
hpa.Spec.GraphdPolicy.Behavior.ScaleUp.SelectPolicy = &selectPolicy
}
if behavior.ScaleDown != nil && behavior.ScaleDown.SelectPolicy == nil {
selectPolicy := autoscalingv2.MaxChangePolicySelect
hpa.Spec.GraphdPolicy.Behavior.ScaleDown.SelectPolicy = &selectPolicy
}
}
}

// getReplicasChangePerPeriod function find all the replica changes per period
func getReplicasChangePerPeriod(periodSeconds int32, scaleEvents []timestampedScaleEvent) int32 {
period := time.Second * time.Duration(periodSeconds)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/component/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ func isPending(pod *corev1.Pod) bool {
return pod.Status.Phase == corev1.PodPending
}

// 1. new pvc is not nil, old pvc is not nil, update storage
func syncPVC(
component v1alpha1.NebulaClusterComponent,
pvcClient kube.PersistentVolumeClaim) error {
Expand All @@ -513,7 +512,8 @@ func syncPVC(
if oldPVC == nil {
continue
}
if volumeClaim.Spec.Resources.Requests.Storage().Cmp(*oldPVC.Spec.Resources.Requests.Storage()) != 0 {
if volumeClaim.Spec.Resources.Requests.Storage().Cmp(*oldPVC.Spec.Resources.Requests.Storage()) == 1 {
klog.Infof("expand PVC %s size to %s", pvcName, volumeClaim.Spec.Resources.Requests.Storage().String())
// only update storage
oldPVC.Spec.Resources.Requests = volumeClaim.Spec.Resources.Requests
if err = pvcClient.UpdatePVC(oldPVC); err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func (c *storagedCluster) syncStoragedWorkload(nc *v1alpha1.NebulaCluster) error
nc.Status.Storaged.Phase == v1alpha1.UpdatePhase {
oldVolumeClaims := extender.GetDataVolumeClaims(oldWorkload)
newVolumeClaims := extender.GetDataVolumeClaims(newWorkload)
// TODO: webhook validating
if len(oldVolumeClaims) != len(newVolumeClaims) {
return fmt.Errorf("update storage data volume claims is not supported")
}
Expand Down

0 comments on commit 51761f6

Please sign in to comment.