Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when detecting k8s not found errors on creating otterize-cluste-uid configmap, causing issues with database integrations #520

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/shared/clusterutils/clusterid.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func GetClusterUID(ctx context.Context) (string, error) {
podNamespace := os.Getenv("POD_NAMESPACE")
configMap, err := k8sclient.CoreV1().ConfigMaps(podNamespace).Get(ctx, OtterizeClusterUIDResourceName, metav1.GetOptions{})
if err != nil {
return "", err // DO NOT wrap this error as it causes the error to not be identified by k8serrors.IsType(err)
return "", errors.Wrap(err)
}

clusterUID, ok := configMap.Data[OtterizeClusterUIDKeyName]
Expand Down Expand Up @@ -76,12 +76,14 @@ func SetClusterUID(ctx context.Context) (string, error) {
func getOrCreateClusterUID(ctx context.Context) (string, error) {
clusterUID, err := GetClusterUID(ctx)
if err != nil {
if k8serrors.IsNotFound(errors.Unwrap(err)) {
clusterUID, err = SetClusterUID(ctx)
if err != nil {
return "", errors.Wrap(err)
if k8sErr := &(k8serrors.StatusError{}); errors.As(err, &k8sErr) {
if k8serrors.IsNotFound(k8sErr) {
clusterUID, err = SetClusterUID(ctx)
if err != nil {
return "", errors.Wrap(err)
}
return clusterUID, nil
}
return clusterUID, nil
}
return "", errors.Wrap(err)
}
Expand Down
Loading