Skip to content

Commit

Permalink
change alligator to sensor (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
orishuss authored Oct 7, 2024
1 parent 05f1a19 commit 690b89f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func validateInstall(ctx context.Context, kubeClient *k8s.Client, releaseName, n
}

if agentEnabled {
if err = waitForAlligators(ctx, kubeClient, namespace, appVersion, deployableNodesCount, sentryHelmContext); err != nil {
if err = waitForSensors(ctx, kubeClient, namespace, appVersion, deployableNodesCount, sentryHelmContext); err != nil {
return err
}
}
Expand Down
68 changes: 34 additions & 34 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ const (
PVC_POLLING_RETRIES = 40
PVC_POLLING_TIMEOUT = time.Minute * 10

ALLIGATORS_POLLING_INTERVAL = time.Second * 15
ALLIGATORS_POLLING_RETRIES = 28
ALLIGATORS_POLLING_TIMEOUT = time.Minute * 7
SENSORS_POLLING_INTERVAL = time.Second * 15
SENSORS_POLLING_RETRIES = 28
SENSORS_POLLING_TIMEOUT = time.Minute * 7

ALLIGATOR_LABEL_SELECTOR = "app=alligator"
BACKEND_LABEL_SELECTOR = "app!=alligator"
PORTAL_LABEL_SELECTOR = "app=portal"
RUNNING_FIELD_SELECTOR = "status.phase=Running"
SENSOR_LABEL_SELECTOR = "app=sensor"
BACKEND_LABEL_SELECTOR = "app!=sensor"
PORTAL_LABEL_SELECTOR = "app=portal"
RUNNING_FIELD_SELECTOR = "status.phase=Running"

WAIT_FOR_PORTAL_FORMAT = "Waiting until cluster establish connectivity"
WAIT_FOR_PVCS_FORMAT = "Waiting until all PVCs are bound (%d/%d PVCs)"
WAIT_FOR_ALLIGATORS_FORMAT = "Waiting until all nodes are monitored (%d/%d Nodes)"
WAIT_FOR_SENSORS_FORMAT = "Waiting until all nodes are monitored (%d/%d Nodes)"
TIMEOUT_INSTALLATION_FORMAT = "Installation takes longer than expected, you can check the status using \"kubectl get pods -n %s\""

PVCS_VALIDATION_EVENT_NAME = "pvcs_validation"
Expand Down Expand Up @@ -117,7 +117,7 @@ var StatusCmd = &cobra.Command{
}
nodesCount := len(nodeList.Items)

if err = waitForAlligators(ctx, kubeClient, namespace, chart.AppVersion(), nodesCount, sentryHelmContext); err != nil {
if err = waitForSensors(ctx, kubeClient, namespace, chart.AppVersion(), nodesCount, sentryHelmContext); err != nil {
return err
}

Expand Down Expand Up @@ -178,7 +178,7 @@ func waitForPortal(ctx context.Context, kubeClient *k8s.Client, namespace, appVe
return err
}

func waitForAlligators(ctx context.Context, kubeClient *k8s.Client, namespace, appVersion string, expectedAlligatorsCount int, sentryHelmContext *sentry_utils.HelmContext) error {
func waitForSensors(ctx context.Context, kubeClient *k8s.Client, namespace, appVersion string, expectedSensorsCount int, sentryHelmContext *sentry_utils.HelmContext) error {
var err error

event := segment.NewEvent(AGENTS_VALIDATION_EVENT_NAME)
Expand All @@ -187,43 +187,43 @@ func waitForAlligators(ctx context.Context, kubeClient *k8s.Client, namespace, a
event.StatusByError(err)
}()

spinner := ui.GlobalWriter.NewSpinner(fmt.Sprintf(WAIT_FOR_ALLIGATORS_FORMAT, 0, expectedAlligatorsCount))
spinner.SetStopMessage(fmt.Sprintf("All nodes are monitored (%d/%d Nodes)", expectedAlligatorsCount, expectedAlligatorsCount))
spinner := ui.GlobalWriter.NewSpinner(fmt.Sprintf(WAIT_FOR_SENSORS_FORMAT, 0, expectedSensorsCount))
spinner.SetStopMessage(fmt.Sprintf("All nodes are monitored (%d/%d Nodes)", expectedSensorsCount, expectedSensorsCount))
spinner.SetStopFailMessage(fmt.Sprintf(TIMEOUT_INSTALLATION_FORMAT, namespace))

spinner.Start()
defer spinner.WriteStop()

runningAlligators := 0
runningSensors := 0

isAlligatorRunningFunc := func() error {
isSensorRunningFunc := func() error {
var err error

if runningAlligators, err = getRunningAlligators(ctx, kubeClient, appVersion, namespace); err != nil {
if runningSensors, err = getRunningSensors(ctx, kubeClient, appVersion, namespace); err != nil {
return err
}

spinner.WriteMessage(fmt.Sprintf(WAIT_FOR_ALLIGATORS_FORMAT, runningAlligators, expectedAlligatorsCount))
spinner.WriteMessage(fmt.Sprintf(WAIT_FOR_SENSORS_FORMAT, runningSensors, expectedSensorsCount))

if runningAlligators >= expectedAlligatorsCount {
if runningSensors >= expectedSensorsCount {
return nil
}

err = errors.New("not all expected alligators are running")
err = errors.New("not all expected sensors are running")
return ui.RetryableError(err)
}

err = spinner.Poll(ctx, isAlligatorRunningFunc, ALLIGATORS_POLLING_INTERVAL, ALLIGATORS_POLLING_TIMEOUT, ALLIGATORS_POLLING_RETRIES)
err = spinner.Poll(ctx, isSensorRunningFunc, SENSORS_POLLING_INTERVAL, SENSORS_POLLING_TIMEOUT, SENSORS_POLLING_RETRIES)

runningAlligatorsStr := fmt.Sprintf("%d/%d", runningAlligators, expectedAlligatorsCount)
sentryHelmContext.RunningAlligators = runningAlligatorsStr
sentry_utils.SetTagOnCurrentScope(sentry_utils.EXPECTED_NODES_COUNT_TAG, fmt.Sprintf("%d", expectedAlligatorsCount))
sentry_utils.SetTagOnCurrentScope(sentry_utils.RUNNING_ALLIGATORS_TAG, runningAlligatorsStr)
runningSensorsStr := fmt.Sprintf("%d/%d", runningSensors, expectedSensorsCount)
sentryHelmContext.RunningSensors = runningSensorsStr
sentry_utils.SetTagOnCurrentScope(sentry_utils.EXPECTED_NODES_COUNT_TAG, fmt.Sprintf("%d", expectedSensorsCount))
sentry_utils.SetTagOnCurrentScope(sentry_utils.RUNNING_SENSORS_TAG, runningSensorsStr)

sentryHelmContext.SetOnCurrentScope()
event.
Set("alligatorsCount", expectedAlligatorsCount).
Set("runningAlligatorsCount", runningAlligators)
Set("sensorsCount", expectedSensorsCount).
Set("runningSensorsCount", runningSensors)

if err == nil {
return nil
Expand All @@ -232,9 +232,9 @@ func waitForAlligators(ctx context.Context, kubeClient *k8s.Client, namespace, a
defer spinner.WriteStopFail()

if errors.Is(err, ui.ErrSpinnerTimeout) {
if runningAlligators > 0 {
if runningSensors > 0 {
spinner.SetWarningSign()
spinner.SetStopFailMessage(fmt.Sprintf("groundcover managed to provision %d/%d nodes", runningAlligators, expectedAlligatorsCount))
spinner.SetStopFailMessage(fmt.Sprintf("groundcover managed to provision %d/%d nodes", runningSensors, expectedSensorsCount))
}

return ErrExecutionPartialSuccess
Expand All @@ -243,27 +243,27 @@ func waitForAlligators(ctx context.Context, kubeClient *k8s.Client, namespace, a
return err
}

func getRunningAlligators(ctx context.Context, kubeClient *k8s.Client, appVersion string, namespace string) (int, error) {
func getRunningSensors(ctx context.Context, kubeClient *k8s.Client, appVersion string, namespace string) (int, error) {
podClient := kubeClient.CoreV1().Pods(namespace)
listOptions := metav1.ListOptions{
LabelSelector: ALLIGATOR_LABEL_SELECTOR,
LabelSelector: SENSOR_LABEL_SELECTOR,
FieldSelector: RUNNING_FIELD_SELECTOR,
}

runningAlligators := 0
runningSensors := 0

podList, err := podClient.List(ctx, listOptions)
if err != nil {
return runningAlligators, err
return runningSensors, err
}

for _, pod := range podList.Items {
if pod.Annotations["groundcover_version"] == appVersion {
runningAlligators++
runningSensors++
}
}

return runningAlligators, nil
return runningSensors, nil
}

func reportPodsStatus(ctx context.Context, kubeClient *k8s.Client, namespace string, sentryHelmContext *sentry_utils.HelmContext) {
Expand All @@ -272,7 +272,7 @@ func reportPodsStatus(ctx context.Context, kubeClient *k8s.Client, namespace str
return
}

agentPodsStatus, err := listPodsStatuses(ctx, kubeClient, namespace, metav1.ListOptions{LabelSelector: ALLIGATOR_LABEL_SELECTOR})
agentPodsStatus, err := listPodsStatuses(ctx, kubeClient, namespace, metav1.ListOptions{LabelSelector: SENSOR_LABEL_SELECTOR})
if err != nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/presets/agent/kernel-5-11.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
agent:
alligator:
sensor:
resources:
requests:
memory: 1Gi
Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/presets/agent/low-resources.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
agent:
alligator:
sensor:
resources:
requests:
cpu: 100m
Expand Down
2 changes: 1 addition & 1 deletion pkg/sentry/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
CLUSTER_NAME_TAG = "cluster.name"
NODES_COUNT_TAG = "nodes.count"
EXPECTED_NODES_COUNT_TAG = "nodes.expected_count"
RUNNING_ALLIGATORS_TAG = "nodes.running_alligators"
RUNNING_SENSORS_TAG = "nodes.running_sensors"
FLUSH_TIMEOUT = time.Second * 2
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/sentry/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type HelmContext struct {
ChartName string `json:",omitempty"`
ReleaseName string `json:",omitempty"`
ChartVersion string `json:",omitempty"`
RunningAlligators string `json:",omitempty"`
RunningSensors string `json:",omitempty"`
PreviousChartVersion string `json:",omitempty"`
ResourcesPresets []string `json:",omitempty"`
ValuesOverride map[string]interface{} `json:",omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions pkg/sentry/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (suite *SentryContextTestSuite) TestHelmContexJsonOmitEmpty() {
func (suite *SentryContextTestSuite) TestHelmContextSetOnCurrentScopeSuccess() {
//prepare
chartVersion := "1.0.0"
runningAlligators := "1/1"
runningSensors := "1/1"
previousChartVersion := "0.9.0"
repoUrl := uuid.New().String()
chartName := uuid.New().String()
Expand All @@ -171,7 +171,7 @@ func (suite *SentryContextTestSuite) TestHelmContextSetOnCurrentScopeSuccess() {
sentryContext.PreviousChartVersion = previousChartVersion
sentryContext.ValuesOverride = valuesOverride
sentryContext.ResourcesPresets = resourcesPresets
sentryContext.RunningAlligators = runningAlligators
sentryContext.RunningSensors = runningSensors

//act
sentryContext.SetOnCurrentScope()
Expand All @@ -187,7 +187,7 @@ func (suite *SentryContextTestSuite) TestHelmContextSetOnCurrentScopeSuccess() {
ChartVersion: chartVersion,
ValuesOverride: valuesOverride,
ResourcesPresets: resourcesPresets,
RunningAlligators: runningAlligators,
RunningSensors: runningSensors,
PreviousChartVersion: previousChartVersion,
},
}
Expand Down

0 comments on commit 690b89f

Please sign in to comment.