Skip to content

Commit

Permalink
Look for Cluster in organization namespace in vintage MCs (#93)
Browse files Browse the repository at this point in the history
* Look for Cluster in organization namespace in vintage MCs

* fix test
  • Loading branch information
anvddriesch authored Oct 24, 2023
1 parent f466bb4 commit 1c6f686
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Look for Cluster in organization namespace in vintage MCs

### Added

- Add option to `setup` to use credentials as base64 encoded variables.
Expand Down
15 changes: 14 additions & 1 deletion pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"context"
"fmt"
"strings"

"github.com/giantswarm/dex-operator/pkg/key"

Expand Down Expand Up @@ -166,12 +167,24 @@ func (s *Service) ReconcileDelete(ctx context.Context) error {
}

func (s *Service) getAPIServerPort(clusterID string, ctx context.Context) (int, error) {
var namespace string
{
if isOrgNamespace(s.app.Namespace) {
namespace = s.app.Namespace
} else {
namespace = "org-" + s.app.GetLabels()[label.Organization]
}
}
cluster := &capi.Cluster{}
if err := s.Get(ctx, types.NamespacedName{
Name: clusterID,
Namespace: s.app.Namespace},
Namespace: namespace},
cluster); err != nil {
return 0, err
}
return int(cluster.Spec.ControlPlaneEndpoint.Port), nil
}

func isOrgNamespace(namespace string) bool {
return strings.HasPrefix(namespace, "org-")
}
8 changes: 4 additions & 4 deletions pkg/auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func TestReconcile(t *testing.T) {
app: &v1alpha1.App{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "example",
Labels: map[string]string{label.Cluster: tc.clusterName},
Namespace: "org-example",
Labels: map[string]string{label.Cluster: tc.clusterName, label.Organization: "example"},
},
},
writeAllGroups: tc.writeAllGroups,
Expand All @@ -103,7 +103,7 @@ func TestReconcile(t *testing.T) {
result := &corev1.ConfigMap{}
if err := service.Client.Get(ctx, types.NamespacedName{
Name: key.GetAuthConfigName(tc.clusterName),
Namespace: "example"},
Namespace: "org-example"},
result); err != nil {
if !apierrors.IsNotFound(err) {
t.Fatal(err)
Expand All @@ -121,7 +121,7 @@ func getTestCluster() *capi.Cluster {
return &capi.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "wc",
Namespace: "example",
Namespace: "org-example",
},
Spec: capi.ClusterSpec{
ControlPlaneEndpoint: capi.APIEndpoint{
Expand Down

0 comments on commit 1c6f686

Please sign in to comment.