generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat(teams): add members to team status #794
Draft
gciezkowski-acc
wants to merge
6
commits into
main
Choose a base branch
from
feat/723_team_controller_store_members
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7f7ce11
feat(teams) Add members to team status (#723)
gciezkowski-acc a6add01
Automatic generation of CRD API Docs
cloud-operator 1affb21
Automatic application of license header
bcc6a00
feat(teams) Unit tests for members in team (#723)
gciezkowski-acc 6795526
Automatic generation of CRD API Docs
cloud-operator b61caaf
Automatic application of license header
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,81 @@ | ||
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package team | ||
|
||
import ( | ||
"context" | ||
|
||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/record" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
greenhouseapisv1alpha1 "github.com/cloudoperators/greenhouse/pkg/apis/greenhouse/v1alpha1" | ||
"github.com/cloudoperators/greenhouse/pkg/lifecycle" | ||
) | ||
|
||
type TeamReconciler struct { | ||
client.Client | ||
recorder record.EventRecorder | ||
} | ||
|
||
// SetupWithManager sets up the controller with the Manager. | ||
func (r *TeamReconciler) SetupWithManager(name string, mgr ctrl.Manager) error { | ||
r.Client = mgr.GetClient() | ||
r.recorder = mgr.GetEventRecorderFor(name) | ||
return ctrl.NewControllerManagedBy(mgr). | ||
Named(name). | ||
For(&greenhouseapisv1alpha1.Team{}). | ||
Complete(r) | ||
} | ||
|
||
func (r *TeamReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
return lifecycle.Reconcile(ctx, r.Client, req.NamespacedName, &greenhouseapisv1alpha1.Team{}, r, r.setStatus()) | ||
} | ||
|
||
func (r *TeamReconciler) EnsureDeleted(_ context.Context, _ lifecycle.RuntimeObject) (ctrl.Result, lifecycle.ReconcileResult, error) { | ||
return ctrl.Result{}, lifecycle.Success, nil | ||
} | ||
|
||
func (r *TeamReconciler) EnsureCreated(ctx context.Context, object lifecycle.RuntimeObject) (ctrl.Result, lifecycle.ReconcileResult, error) { | ||
return ctrl.Result{}, lifecycle.Success, nil | ||
} | ||
|
||
func (r *TeamReconciler) setStatus() lifecycle.Conditioner { | ||
return func(ctx context.Context, object lifecycle.RuntimeObject) { | ||
team, ok := object.(*greenhouseapisv1alpha1.Team) | ||
if !ok { | ||
return | ||
} | ||
|
||
var members []greenhouseapisv1alpha1.User | ||
teamMembershipList := new(greenhouseapisv1alpha1.TeamMembershipList) | ||
|
||
err := r.List(ctx, teamMembershipList) | ||
if err != nil { | ||
ctrl.Log.Error(err, "Failed to list team memberships") | ||
return | ||
} | ||
|
||
for _, member := range teamMembershipList.Items { | ||
if !hasOwnerReference(member.OwnerReferences, team.Kind, team.Name) { | ||
continue | ||
} | ||
|
||
members = append(members, member.Spec.Members...) | ||
} | ||
|
||
team.Status.Members = members | ||
} | ||
} | ||
|
||
func hasOwnerReference(ownerReferences []v1.OwnerReference, kind, name string) bool { | ||
for _, ownerReference := range ownerReferences { | ||
if ownerReference.Kind == kind && ownerReference.Name == name { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be replaced with
greenhouse/pkg/clientutil/owner_reference.go
Lines 10 to 18 in 2a5d694