Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
anupama2501 committed Oct 29, 2024
1 parent 8402f43 commit 7c34bb5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
18 changes: 12 additions & 6 deletions tests/v2/actions/charts/stackstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/rancher/shepherd/extensions/defaults"
"github.com/rancher/shepherd/pkg/api/steve/catalog/types"
"github.com/rancher/shepherd/pkg/wait"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/watch"
)
Expand All @@ -28,13 +29,14 @@ const (
)

var (
timeoutSeconds = int64(defaults.FiveMinuteTimeout)
timeoutSeconds = int64(defaults.TwoMinuteTimeout)
)

// InstallStackstateAgentChart is a private helper function that returns chart install action with stack state agent and payload options.
func InstallStackstateAgentChart(client *rancher.Client, installOptions *InstallOptions, stackstateConfigs *observability.StackStateConfig, systemProjectID string) error {
serverSetting, err := client.Management.Setting.ByID(serverURLSettingID)
if err != nil {
log.Info("Error getting server setting.")
return err
}

Expand All @@ -49,6 +51,7 @@ func InstallStackstateAgentChart(client *rancher.Client, installOptions *Install

catalogClient, err := client.GetClusterCatalogClient(installOptions.Cluster.ID)
if err != nil {
log.Info("Error getting catalogClient")
return err
}

Expand All @@ -71,12 +74,12 @@ func InstallStackstateAgentChart(client *rancher.Client, installOptions *Install

err = wait.WatchWait(watchAppInterface, func(event watch.Event) (ready bool, err error) {
chart := event.Object.(*catalogv1.App)
if event.Type == watch.Deleted {
if event.Type == watch.Error {
return false, fmt.Errorf("there was an error uninstalling stackstate agent chart")
} else if event.Type == watch.Deleted {
return true, nil
} else if chart == nil {
return true, nil
} else if event.Type == watch.Error {
return false, fmt.Errorf("there was an error uninstalling stackstate agent chart")
}
return false, nil
})
Expand Down Expand Up @@ -130,16 +133,17 @@ func InstallStackstateAgentChart(client *rancher.Client, installOptions *Install

err = catalogClient.InstallChart(chartInstallAction, RancherPartnerChartRepo)
if err != nil {
log.Info("Errored installing the chart")
return err
}

// wait for chart to be fully deployed
timeoutSeconds = int64(defaults.TenMinuteTimeout)
watchAppInterface, err := catalogClient.Apps(StackstateNamespace).Watch(context.TODO(), metav1.ListOptions{
FieldSelector: "metadata.name=" + StackstateK8sAgent,
TimeoutSeconds: &timeoutSeconds,
TimeoutSeconds: &defaults.WatchTimeoutSeconds,
})
if err != nil {
log.Info("Unable to obtain the installed app ")
return err
}

Expand All @@ -152,7 +156,9 @@ func InstallStackstateAgentChart(client *rancher.Client, installOptions *Install
}
return false, nil
})

if err != nil {
log.Info("Unable to obtain the status of the installed app ")
return err
}
return nil
Expand Down
16 changes: 9 additions & 7 deletions tests/v2/actions/uiplugins/stackstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
)

var (
timeoutSeconds = int64(defaults.FiveMinuteTimeout)
timeoutSeconds = int64(defaults.TwoMinuteTimeout)
)

// InstallObservabilityUiPlugin is a helper function that installs the observability extension chart in the local cluster of rancher.
Expand All @@ -43,7 +43,6 @@ func InstallObservabilityUiPlugin(client *rancher.Client, installExtensionOption
if err != nil {
return err
}
log.Info("Uninstalled observability extension successfully.")

watchAppInterface, err := catalogClient.Apps(stackstateExtensionNamespace).Watch(context.TODO(), metav1.ListOptions{
FieldSelector: "metadata.name=" + stackstateExtensionsName,
Expand All @@ -55,14 +54,16 @@ func InstallObservabilityUiPlugin(client *rancher.Client, installExtensionOption

err = wait.WatchWait(watchAppInterface, func(event watch.Event) (ready bool, err error) {
chart := event.Object.(*v1.App)
if chart == nil {
return true, nil
if event.Type == watch.Error {
return false, fmt.Errorf("there was an error uninstalling stackstate extension")
} else if event.Type == watch.Deleted {
log.Info("Uninstalled observability extension successfully.")
return true, nil
} else if chart == nil {
return true, nil
} else if event.Type == watch.Error {
return false, fmt.Errorf("there was an error uninstalling stackstate extension")
}
return false, nil

})

return err
Expand All @@ -76,7 +77,7 @@ func InstallObservabilityUiPlugin(client *rancher.Client, installExtensionOption

watchAppInterface, err := catalogClient.Apps(stackstateExtensionNamespace).Watch(context.TODO(), metav1.ListOptions{
FieldSelector: "metadata.name=" + stackstateExtensionsName,
TimeoutSeconds: &timeoutSeconds,
TimeoutSeconds: &defaults.WatchTimeoutSeconds,
})
if err != nil {
return err
Expand Down Expand Up @@ -145,6 +146,7 @@ func CreateExtensionsRepo(client *rancher.Client, rancherUiPluginsName, uiExtens
if event.Type == watch.Error {
return false, fmt.Errorf("there was an error deleting the cluster repo")
} else if event.Type == watch.Deleted {
log.Info("Removed extensions repo successfully.")
return true, nil
}
return false, nil
Expand Down

0 comments on commit 7c34bb5

Please sign in to comment.