Skip to content

Commit

Permalink
Merge branch 'main' into feat/scim_all_users
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijith-darshan committed Dec 12, 2024
2 parents c0e1812 + 7e98462 commit be11c02
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 71 deletions.
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/epic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ✨ Epic
description: Create an epic
title: "[EPIC] - <title>"
body:
- type: textarea
id: description
attributes:
label: Description
placeholder: What problem does it solve? Why is it important?
- type: textarea
id: objectives
attributes:
label: Objectives
placeholder: List the high-level objectives or goals of this epic.
value: |
- Objective 1
- Objective 2
- Objective 3
- type: textarea
id: acceptance-criteria
attributes:
label: Acceptance Criteria
placeholder: Define the criteria that must be met for this epic to be considered complete
value: |
- [ ] Criterion 1
- [ ] Criterion 2
- [ ] Criterion 3
- type: textarea
id: dependencies
attributes:
label: Dependencies
placeholder: Identify any other epics, issues, or tasks that this epic depends on.
value: |
- Dependency 1
- Dependency 2
- Dependency 3
- type: textarea
id: additional-notes
attributes:
label: Additioinal Notes
placeholder: Any additional information, context, or considerations.
2 changes: 1 addition & 1 deletion charts/greenhouse/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: v2
name: greenhouse
description: A Helm chart for deploying greenhouse
type: application
version: 0.4.4
version: 0.4.5
appVersion: "0.1.0"

dependencies:
Expand Down
21 changes: 0 additions & 21 deletions charts/idproxy/templates/servicemonitor.yaml

This file was deleted.

49 changes: 0 additions & 49 deletions charts/manager/templates/servicemonitor.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions docs/reference/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,58 @@ <h3 id="greenhouse.sap/v1alpha1.ClusterOptionOverride">ClusterOptionOverride
</table>
</div>
</div>
<h3 id="greenhouse.sap/v1alpha1.ClusterSelector">ClusterSelector
</h3>
<p>ClusterSelector specifies a selector for clusters by name or by label with the option to exclude specific clusters.</p>
<div class="md-typeset__scrollwrap">
<div class="md-typeset__table">
<table>
<thead>
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>clusterName</code><br>
<em>
string
</em>
</td>
<td>
<p>Name of a single Cluster to select.</p>
</td>
</tr>
<tr>
<td>
<code>labelSelector</code><br>
<em>
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#labelselector-v1-meta">
Kubernetes meta/v1.LabelSelector
</a>
</em>
</td>
<td>
<p>LabelSelector is a label query over a set of Clusters.</p>
</td>
</tr>
<tr>
<td>
<code>excludeList</code><br>
<em>
[]string
</em>
</td>
<td>
<p>ExcludeList is a list of Cluster names to exclude from LabelSelector query.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3 id="greenhouse.sap/v1alpha1.ClusterSpec">ClusterSpec
</h3>
<p>
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/greenhouse/v1alpha1/api_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/cloudoperators/greenhouse/pkg/test"
)

func TestAPI(t *testing.T) {
Expand All @@ -16,7 +18,10 @@ func TestAPI(t *testing.T) {
}

var _ = BeforeSuite(func() {
test.TestBeforeSuite()
})

var _ = AfterSuite(func() {
By("tearing down the test environment")
test.TestAfterSuite()
})
54 changes: 54 additions & 0 deletions pkg/apis/greenhouse/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
package v1alpha1

import (
"context"
"fmt"
"slices"

apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// HelmChartReference references a Helm Chart in a chart repository.
Expand Down Expand Up @@ -48,3 +55,50 @@ type UIApplicationReference struct {
// Version of the frontend application.
Version string `json:"version"`
}

// ClusterSelector specifies a selector for clusters by name or by label with the option to exclude specific clusters.
type ClusterSelector struct {
// Name of a single Cluster to select.
Name string `json:"clusterName,omitempty"`
// LabelSelector is a label query over a set of Clusters.
LabelSelector metav1.LabelSelector `json:"labelSelector,omitempty"`
// ExcludeList is a list of Cluster names to exclude from LabelSelector query.
ExcludeList []string `json:"excludeList,omitempty"`
}

// ListClusters returns the list of Clusters that match the ClusterSelector's Name or LabelSelector with applied ExcludeList.
// If the Name or LabelSelector does not return any cluster, an empty ClusterList is returned without error.
func (cs *ClusterSelector) ListClusters(ctx context.Context, c client.Client, namespace string) (*ClusterList, error) {
if cs.Name != "" {
cluster := new(Cluster)
err := c.Get(ctx, types.NamespacedName{Name: cs.Name, Namespace: namespace}, cluster)
if err != nil {
if apierrors.IsNotFound(err) {
return &ClusterList{}, nil
}
return nil, err
}
return &ClusterList{Items: []Cluster{*cluster}}, nil
}

labelSelector, err := metav1.LabelSelectorAsSelector(&cs.LabelSelector)
if err != nil {
return nil, err
}
var clusters = new(ClusterList)
err = c.List(ctx, clusters, client.InNamespace(namespace), client.MatchingLabelsSelector{Selector: labelSelector})
if err != nil {
return nil, err
}
if len(clusters.Items) == 0 || len(cs.ExcludeList) == 0 {
return clusters, nil
}

clusters.Items = slices.DeleteFunc(clusters.Items, func(cluster Cluster) bool {
return slices.ContainsFunc(cs.ExcludeList, func(excludedClusterName string) bool {
return cluster.Name == excludedClusterName
})
})

return clusters, nil
}
111 changes: 111 additions & 0 deletions pkg/apis/greenhouse/v1alpha1/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
// SPDX-License-Identifier: Apache-2.0

package v1alpha1_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/cloudoperators/greenhouse/pkg/apis/greenhouse/v1alpha1"
"github.com/cloudoperators/greenhouse/pkg/test"
)

var (
setup *test.TestSetup
clusterA *v1alpha1.Cluster
clusterB *v1alpha1.Cluster
clusterC *v1alpha1.Cluster
clusterD *v1alpha1.Cluster
clusterE *v1alpha1.Cluster
clusterF *v1alpha1.Cluster
clusterG *v1alpha1.Cluster
)

var _ = Describe("ClusterSelector type's ListClusters method", Ordered, func() {
BeforeAll(func() {
setup = test.NewTestSetup(test.Ctx, test.K8sClient, "test-org")

By("creating test clusters")
clusterA = setup.CreateCluster(test.Ctx, "cluster-a")
clusterB = setup.CreateCluster(test.Ctx, "cluster-b", test.WithLabel("group", "first"))
clusterC = setup.CreateCluster(test.Ctx, "cluster-c", test.WithLabel("group", "second"))
clusterD = setup.CreateCluster(test.Ctx, "cluster-d", test.WithLabel("group", "first"))
clusterE = setup.CreateCluster(test.Ctx, "cluster-e", test.WithLabel("group", "second"))
clusterF = setup.CreateCluster(test.Ctx, "cluster-f", test.WithLabel("group", "second"))
clusterG = setup.CreateCluster(test.Ctx, "cluster-g", test.WithLabel("group", "second"))
})

AfterAll(func() {
By("cleaning up test clusters")
test.EventuallyDeleted(test.Ctx, setup.Client, clusterA)
test.EventuallyDeleted(test.Ctx, setup.Client, clusterB)
test.EventuallyDeleted(test.Ctx, setup.Client, clusterC)
test.EventuallyDeleted(test.Ctx, setup.Client, clusterD)
test.EventuallyDeleted(test.Ctx, setup.Client, clusterE)
test.EventuallyDeleted(test.Ctx, setup.Client, clusterF)
test.EventuallyDeleted(test.Ctx, setup.Client, clusterG)
})

It("should return correct cluster by Name", func() {
By("setting up a ClusterSelector")
cs := new(v1alpha1.ClusterSelector)
cs.Name = "cluster-a"

By("executing ListClusters method")
clusters, err := cs.ListClusters(test.Ctx, setup.Client, setup.Namespace())
Expect(err).ToNot(HaveOccurred(), "there should be no error listing the clusters")

By("checking returned clusters")
Expect(clusters.Items).To(HaveLen(1), "ListClusters should match exactly one cluster")
Expect(clusters.Items[0].Name).To(Equal("cluster-a"), "ListClusters should return cluster with name cluster-a")
})

It("should list all clusters matching LabelSelector", func() {
By("setting up a ClusterSelector")
cs := new(v1alpha1.ClusterSelector)
cs.LabelSelector = v1.LabelSelector{
MatchLabels: map[string]string{
"group": "first",
},
}

By("executing ListClusters method")
clusters, err := cs.ListClusters(test.Ctx, setup.Client, setup.Namespace())
Expect(err).ToNot(HaveOccurred(), "there should be no error listing the clusters")

By("checking returned clusters")
Expect(clusters.Items).To(HaveLen(2), "ListClusters should match exactly two clusters")

clusterNames := make([]string, 0, 2)
for _, v := range clusters.Items {
clusterNames = append(clusterNames, v.Name)
}
Expect(clusterNames).To(ConsistOf("cluster-b", "cluster-d"), "ListClusters should return clusters with names cluster-b and cluster-d")
})

It("should list all clusters matching LabelSelector except for those in ExcludeList", func() {
By("setting up a ClusterSelector")
cs := new(v1alpha1.ClusterSelector)
cs.LabelSelector = v1.LabelSelector{
MatchLabels: map[string]string{
"group": "second",
},
}
cs.ExcludeList = []string{"cluster-c", "cluster-f"}

By("executing ListClusters method")
clusters, err := cs.ListClusters(test.Ctx, setup.Client, setup.Namespace())
Expect(err).ToNot(HaveOccurred(), "there should be no error listing the clusters")

By("checking returned clusters")
Expect(clusters.Items).To(HaveLen(2), "ListClusters should match exactly two clusters")

clusterNames := make([]string, 0, 2)
for _, v := range clusters.Items {
clusterNames = append(clusterNames, v.Name)
}
Expect(clusterNames).To(ConsistOf("cluster-e", "cluster-g"), "ListClusters should return clusters with names cluster-e and cluster-g")
})
})
Loading

0 comments on commit be11c02

Please sign in to comment.