Skip to content

Commit

Permalink
fix bugs (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaByte875 authored Nov 14, 2023
1 parent 8011afa commit 17ace23
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 32 deletions.
23 changes: 12 additions & 11 deletions apis/apps/v1alpha1/nebulacluster_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,24 +312,25 @@ func generateAgentContainer(c NebulaClusterComponent, init bool) corev1.Containe
}
}

agentImage := defaultAgentImage
container := corev1.Container{
Name: AgentSidecarContainerName,
Image: defaultAgentImage,
Command: cmd,
}
imagePullPolicy := nc.Spec.ImagePullPolicy
if imagePullPolicy != nil {
container.ImagePullPolicy = *imagePullPolicy
}
if nc.Spec.Agent != nil {
var agentImage string
if nc.Spec.Agent.Image != "" {
agentImage = nc.Spec.Agent.Image
}
if nc.Spec.Agent.Version != "" {
agentImage = fmt.Sprintf("%s:%s", agentImage, nc.Spec.Agent.Version)
}
}
container := corev1.Container{
Name: AgentSidecarContainerName,
Image: agentImage,
Command: cmd,
Resources: nc.Spec.Agent.Resources,
}
imagePullPolicy := nc.Spec.ImagePullPolicy
if imagePullPolicy != nil {
container.ImagePullPolicy = *imagePullPolicy
container.Image = agentImage
container.Resources = nc.Spec.Agent.Resources
}

if nc.IsBREnabled() {
Expand Down
1 change: 1 addition & 0 deletions apis/apps/v1alpha1/nebulacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type NebulaClusterSpec struct {
// +optional
EnableAutoFailover *bool `json:"enableAutoFailover,omitempty"`

// +kubebuilder:default="5m"
// +optional
FailoverPeriod metav1.Duration `json:"failoverPeriod,omitempty"`

Expand Down
2 changes: 1 addition & 1 deletion apis/autoscaling/v1alpha1/nebulaautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var (
// DefaultPollingPeriod is the default period between 2 autoscaling API polls.
DefaultPollingPeriod = 15 * time.Second
DefaultPollingPeriod = 30 * time.Second
)

type NebulaAutoscalerConditionType string
Expand Down
1 change: 1 addition & 0 deletions charts/nebula-operator/crds/nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3187,6 +3187,7 @@ spec:
- image
type: object
failoverPeriod:
default: 5m
type: string
graphd:
properties:
Expand Down
1 change: 1 addition & 0 deletions config/crd/bases/apps.nebula-graph.io_nebulaclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3187,6 +3187,7 @@ spec:
- image
type: object
failoverPeriod:
default: 5m
type: string
graphd:
properties:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/graphd_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *graphdCluster) syncGraphdWorkload(nc *v1alpha1.NebulaCluster) error {
if !notExist {
// TODO: validate the timestamp format
timestamp, ok := oldWorkload.GetAnnotations()[annotation.AnnRestartTimestamp]
if ok {
if ok && timestamp != "" {
if err := extender.SetTemplateAnnotations(newWorkload,
map[string]string{annotation.AnnRestartTimestamp: timestamp}); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/metad_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *metadCluster) syncMetadWorkload(nc *v1alpha1.NebulaCluster) error {

if !notExist {
timestamp, ok := oldWorkload.GetAnnotations()[annotation.AnnRestartTimestamp]
if ok {
if ok && timestamp != "" {
if err := extender.SetTemplateAnnotations(newWorkload,
map[string]string{annotation.AnnRestartTimestamp: timestamp}); err != nil {
return err
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/component/storaged_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (c *storagedCluster) syncStoragedWorkload(nc *v1alpha1.NebulaCluster) error

if !notExist {
timestamp, ok := oldWorkload.GetAnnotations()[annotation.AnnRestartTimestamp]
if ok {
if ok && timestamp != "" {
if err := extender.SetTemplateAnnotations(newWorkload,
map[string]string{annotation.AnnRestartTimestamp: timestamp}); err != nil {
return err
Expand Down Expand Up @@ -288,6 +288,10 @@ func (c *storagedCluster) syncNebulaClusterStatus(
_ = metaClient.Disconnect()
}()

if !nc.IsAutoFailoverEnabled() {
return syncComponentStatus(nc.StoragedComponent(), &nc.Status.Storaged.ComponentStatus, oldWorkload)
}

hostItems, err := metaClient.ListHosts(meta.ListHostType_STORAGE)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/component/storaged_failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (

const (
PVCProtectionFinalizer = "kubernetes.io/pvc-protection"
RestartTolerancePeriod = time.Minute * 1
RestartTolerancePeriod = time.Minute * 2
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ func (u *nebulaClusterConditionUpdater) updateReadyCondition(nc *v1alpha1.Nebula
case !allWorkloadsAreUpToDate(nc):
reason = condition.WorkloadNotUpToDate
message = "Workload is in progress"
case !nc.GraphdComponent().IsReady():
reason = condition.GraphdUnhealthy
message = "Graphd is not healthy"
case !nc.MetadComponent().IsReady():
reason = condition.MetadUnhealthy
message = "Metad is not healthy"
case !nc.IsStoragedAvailable():
reason = condition.StoragedUnhealthy
message = "Storaged is not healthy"
case !nc.GraphdComponent().IsReady():
reason = condition.GraphdUnhealthy
message = "Graphd is not healthy"
default:
status = corev1.ConditionTrue
reason = condition.WorkloadReady
Expand Down
9 changes: 4 additions & 5 deletions pkg/controller/nebulacluster/nebula_cluster_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ func (c *defaultNebulaClusterControl) UpdateNebulaCluster(nc *v1alpha1.NebulaClu
}

c.conditionUpdater.Update(nc)

if apiequality.Semantic.DeepEqual(&nc.Status, oldStatus) && nc.IsConditionReady() {
return errorutils.NewAggregate(errs)
}

nc.Status.ObservedGeneration = nc.Generation
if err := c.nebulaClient.UpdateNebulaClusterStatus(nc.DeepCopy()); err != nil {
errs = append(errs, err)
}

if apiequality.Semantic.DeepEqual(&nc.Status, oldStatus) && nc.IsReady() {
return errorutils.NewAggregate(errs)
}

if !nc.IsConditionReady() {
errs = append(errs, utilerrors.ReconcileErrorf("waiting for nebulacluster ready"))
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/controller/nebularestore/nebula_restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ func (rm *restoreManager) syncRestoreProcess(rt *v1alpha1.NebulaRestore) error {
if rt.Spec.BR.ClusterNamespace != nil {
ns = *rt.Spec.BR.ClusterNamespace
}
original, err := rm.clientSet.NebulaCluster().GetNebulaCluster(ns, originalName)
if err != nil {
return err
}

restoredName, err := rm.getRestoredName(rt)
if err != nil {
Expand All @@ -125,6 +129,7 @@ func (rm *restoreManager) syncRestoreProcess(rt *v1alpha1.NebulaRestore) error {
}
nc.Annotations = nil
nc.Spec.Storaged.EnableForceUpdate = nil
nc.Spec.EnableAutoFailover = original.Spec.EnableAutoFailover
if err := rm.clientSet.NebulaCluster().UpdateNebulaCluster(nc); err != nil {
return fmt.Errorf("remove cluster [%s/%s] annotations failed: %v", ns, restoredName, err)
}
Expand All @@ -141,11 +146,6 @@ func (rm *restoreManager) syncRestoreProcess(rt *v1alpha1.NebulaRestore) error {
})
}

original, err := rm.clientSet.NebulaCluster().GetNebulaCluster(ns, originalName)
if err != nil {
return err
}

options, err := nebula.ClientOptions(original, nebula.SetIsMeta(true))
if err != nil {
return err
Expand Down Expand Up @@ -343,6 +343,7 @@ func (rm *restoreManager) genNebulaCluster(restoredName string, rt *v1alpha1.Neb
nc.Spec.Storaged.InitContainers = append(nc.Spec.Storaged.InitContainers, v1alpha1.GenerateInitAgentContainer(nc.StoragedComponent()))

nc.Spec.Storaged.EnableForceUpdate = pointer.Bool(true)
nc.Spec.EnableAutoFailover = nil
if rt.Spec.NodeSelector != nil {
nc.Spec.NodeSelector = rt.Spec.NodeSelector
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/nebulacluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (c *nebulaClusterClient) UpdateNebulaClusterStatus(nc *v1alpha1.NebulaClust
return err
}

if reflect.DeepEqual(status, ncClone.Status) {
if reflect.DeepEqual(*status, ncClone.Status) {
return nil
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/util/extender/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"strconv"
"strings"
"time"

apiequality "k8s.io/apimachinery/pkg/api/equality"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -303,7 +302,7 @@ func SetRestartTimestamp(obj *unstructured.Unstructured) error {
for k, v := range obj.GetAnnotations() {
annotations[k] = v
}
annotations[annotation.AnnRestartTimestamp] = time.Now().Format(time.RFC3339)
annotations[annotation.AnnRestartTimestamp] = ""
obj.SetAnnotations(annotations)
return nil
}
Expand Down

0 comments on commit 17ace23

Please sign in to comment.