generated from giantswarm/template-operator
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change GetOrganization to rely on the namespace (#1185)
* Change GetOrganization to rely on the namespace * Rely on namespace label for organization --------- Co-authored-by: Mohamed Chiheb <[email protected]> Co-authored-by: QuentinBisson <[email protected]>
- Loading branch information
1 parent
8a058d0
commit a7e3e10
Showing
51 changed files
with
2,139 additions
and
544 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package organization | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
"github.com/giantswarm/prometheus-meta-operator/v2/service/key" | ||
) | ||
|
||
const ( | ||
DefaultOrganization string = "giantswarm" | ||
OrganizationLabel string = "giantswarm.io/organization" | ||
) | ||
|
||
type Reader interface { | ||
Read(ctx context.Context, cluster metav1.Object) (string, error) | ||
} | ||
|
||
type NamespaceReader struct { | ||
client kubernetes.Interface | ||
installation string | ||
provider string | ||
} | ||
|
||
func NewNamespaceReader(client kubernetes.Interface, installation string, provider string) Reader { | ||
return NamespaceReader{client, installation, provider} | ||
} | ||
|
||
func (r NamespaceReader) Read(ctx context.Context, cluster metav1.Object) (string, error) { | ||
// Vintage MC | ||
if key.IsManagementCluster(r.installation, cluster) && !key.IsCAPIManagementCluster(r.provider) { | ||
return DefaultOrganization, nil | ||
} | ||
|
||
// For the rest, we extract the organization name from the namespace labels | ||
namespace, err := r.client.CoreV1().Namespaces().Get(ctx, cluster.GetNamespace(), metav1.GetOptions{}) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if organization, ok := namespace.Labels[OrganizationLabel]; ok { | ||
return organization, nil | ||
} | ||
return "", errors.New("cluster namespace missing organization label") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.