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

Look for Cluster in organization namespace in vintage MCs #93

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
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
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
Loading