Skip to content

Commit

Permalink
Merge branch 'main' into avivzohari/sc-20013/add-vector-to-cli-low-pr…
Browse files Browse the repository at this point in the history
…eset
  • Loading branch information
avivzgroundcover authored Oct 11, 2024
2 parents df15752 + 2704aef commit 1b42d65
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 72 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ builds:
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
Expand Down
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,54 @@ We use the following categories for changes:

### Security

## [0.22.4] 2024-10-07

### Added

### Changed

### Fixed

- Waiting for sensor pods instead of alligator pods [#sc-19833]

### Removed

### Deprecated

### Security

## [0.22.3] 2024-09-17

### Added

- Support groundcover CLI in windows [#sc-19269]

### Changed

### Fixed

### Removed

### Deprecated

### Security

## [0.22.2] 2024-07-04

### Added

- support inCloud validation flow [#sc-16561]

### Changed

### Fixed

### Removed

### Deprecated

### Security

## [0.22.1] 2024-06-03

### Added
Expand All @@ -49,7 +97,9 @@ We use the following categories for changes:
### Added

### Changed

- Datasource key generation based on backend name instead of cluster [sc-16014]

### Fixed

### Removed
Expand Down
33 changes: 19 additions & 14 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,24 @@ func runDeployCmd(cmd *cobra.Command, args []string) error {
return err
}

agentEnabled := true
backendEnabled := true
if backendValues, ok := chartValues["backend"]; ok {
if isEnabled, ok := backendValues.(map[string]interface{})["enabled"]; ok {
if enabled, ok := isEnabled.(bool); ok && !enabled {
backendName := clusterName

if globalValues, ok := chartValues["global"].(map[string]interface{}); ok {
if backendValues, ok := globalValues["backend"].(map[string]interface{}); ok {
if backendNameOverride, ok := backendValues["name"].(string); ok {
backendName = backendNameOverride
}

if isEnabled, ok := backendValues["enabled"].(bool); ok && !isEnabled {
backendName = ""
backendEnabled = false
}
}
}

agentEnabled := true
if agentValues, ok := chartValues["agent"]; ok {
if isEnabled, ok := agentValues.(map[string]interface{})["enabled"]; ok {
if enabled, ok := isEnabled.(bool); ok && !enabled {
if agentValues, ok := globalValues["agent"].(map[string]interface{}); ok {
if isEnabled, ok := agentValues["enabled"].(bool); ok && !isEnabled {
agentEnabled = false
}
}
Expand All @@ -234,7 +239,7 @@ func runDeployCmd(cmd *cobra.Command, args []string) error {
return err
}

if err = validateInstall(ctx, kubeClient, releaseName, namespace, chart.AppVersion(), tenantUUID, clusterName, len(deployableNodes), isAuthenticated, agentEnabled, backendEnabled, sentryHelmContext); err != nil {
if err = validateInstall(ctx, kubeClient, releaseName, namespace, chart.AppVersion(), tenantUUID, backendName, clusterName, len(deployableNodes), isAuthenticated, agentEnabled, backendEnabled, sentryHelmContext); err != nil {
return err
}

Expand Down Expand Up @@ -442,7 +447,7 @@ func installHelmRelease(ctx context.Context, helmClient *helm.Client, releaseNam
return err
}

func validateInstall(ctx context.Context, kubeClient *k8s.Client, releaseName, namespace, appVersion, tenantUUID, clusterName string, deployableNodesCount int, isAuthenticated, agentEnabled, backendEnabled bool, sentryHelmContext *sentry_utils.HelmContext) error {
func validateInstall(ctx context.Context, kubeClient *k8s.Client, releaseName, namespace, appVersion, tenantUUID, backendName, clusterName string, deployableNodesCount int, isAuthenticated, agentEnabled, backendEnabled bool, sentryHelmContext *sentry_utils.HelmContext) error {
var err error

defer reportPodsStatus(ctx, kubeClient, namespace, sentryHelmContext)
Expand All @@ -460,13 +465,13 @@ func validateInstall(ctx context.Context, kubeClient *k8s.Client, releaseName, n
}

if isAuthenticated {
if err = validateClusterRegistered(ctx, tenantUUID, clusterName); err != nil {
if err = validateClusterRegistered(ctx, tenantUUID, backendName, clusterName); err != nil {
return err
}
}

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 All @@ -476,7 +481,7 @@ func validateInstall(ctx context.Context, kubeClient *k8s.Client, releaseName, n
return nil
}

func validateClusterRegistered(ctx context.Context, tenantUUID, clusterName string) error {
func validateClusterRegistered(ctx context.Context, tenantUUID, backendName, clusterName string) error {
var err error

event := segment.NewEvent(CLUSTER_REGISTRATION_EVENT_NAME)
Expand All @@ -492,7 +497,7 @@ func validateClusterRegistered(ctx context.Context, tenantUUID, clusterName stri

apiClient := api.NewClient(auth0Token)

if err = apiClient.PollIsClusterExist(ctx, tenantUUID, clusterName); err != nil {
if err = apiClient.PollIsClusterExist(ctx, tenantUUID, backendName, clusterName); 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
1 change: 1 addition & 0 deletions pkg/api/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type BackendInfo struct {
Online bool `json:"online"`
Licensed bool `json:"licensed"`
Status string `json:"status"`
InCloud bool `json:"inCloud"`
}

func (client *Client) BackendsList(tenantUUID string) ([]BackendInfo, error) {
Expand Down
Loading

0 comments on commit 1b42d65

Please sign in to comment.