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

ASC-402: Copy the SA token of sub-spaces only for specific tiers #902

Closed

Conversation

Kartikey-star
Copy link
Contributor

Acceptance Criteria
The SpaceRequest_controller copies the secret only for specific tiers like appstudio-env one
It is possible to create a sub-space using any other tier like appstudio or base1ns
If the SA token copy part is not supported for the provisioned tier, then the SpaceRequest.Status has corresponding information about it

@openshift-ci
Copy link

openshift-ci bot commented Oct 23, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci
Copy link

openshift-ci bot commented Oct 23, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Kartikey-star
Once this PR has been reviewed and has the lgtm label, please assign matousjobanek for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: Kartikey Mamgain <kmamgain@redhat.com>
Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍

I've added few minor comments. Also could you please add some tests.

@@ -237,9 +239,9 @@ func (r *Reconciler) updateExistingSubSpace(ctx context.Context, spaceRequest *t
}

// validateNSTemplateTier checks if the provided tierName in the spaceRequest exists and is valid
func (r *Reconciler) validateNSTemplateTier(ctx context.Context, tierName string) error {
func (r *Reconciler) validateNSTemplateTier(ctx context.Context, tierName string) (toolchainv1alpha1.NSTemplateTier, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about returning a pointer? This way you could return tier or nil.

Suggested change
func (r *Reconciler) validateNSTemplateTier(ctx context.Context, tierName string) (toolchainv1alpha1.NSTemplateTier, error) {
func (r *Reconciler) validateNSTemplateTier(ctx context.Context, tierName string) (*toolchainv1alpha1.NSTemplateTier, error) {

@@ -25,7 +25,7 @@ objects:
kind: ServiceAccount
metadata:
namespace: ${SPACE_NAME}-env
name: namespace-manager
name: ${SERVICE_ACCOUNT_NAME}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is fine to hard code the name here and in the tier.yaml. Also because unless I'm missing something, you are not populating this variable SERVICE_ACCOUNT_NAME right now.

@@ -20,10 +20,13 @@ objects:
templateRef: ${MAINTAINER_TEMPL_REF}
contributor:
templateRef: ${CONTRIBUTOR_TEMPL_REF}
spaceRequestConfig:
serviceAccountName: ${SERVICE_ACCOUNT_NAME}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above, we could hard code the name here I guess.

Signed-off-by: Kartikey Mamgain <kmamgain@redhat.com>
Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

I have few minor comments.

// create a token request for the admin service account
token, err := restclient.CreateTokenRequest(subSpaceTargetCluster.RESTClient, types.NamespacedName{
Namespace: namespace,
Name: toolchainv1alpha1.AdminServiceAccountName,
Name: serviceAccountName,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there are few other occurrences to be replaced, line 508 and 511. Could you please replace those as well?

if tierName == "" {
return fmt.Errorf("tierName cannot be blank")
return &toolchainv1alpha1.NSTemplateTier{}, fmt.Errorf("tierName cannot be blank")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but we could just return nil here

Suggested change
return &toolchainv1alpha1.NSTemplateTier{}, fmt.Errorf("tierName cannot be blank")
return nil, fmt.Errorf("tierName cannot be blank")

Comment on lines +395 to +396
appstudioTier.Spec.SpaceRequestConfig.ServiceAccountName = "manager"
t.Run("failure service account not present", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is testing the case in which the service account doesn't exist. For this I would rather create a new tier that has a service account which doesn't exist or just configure gock at line 403 to return a different SA name, something like:

commontest.SetupGockForServiceAccounts(t, member1.APIEndpoint, types.NamespacedName{
				Name:      "another-sa-name",
				Namespace: "jane-env",
			})

Also, unless I'm missing something, I don't see a test that:

  • uses a tier which has .Spec.SpaceRequestConfig unset
  • verifies that spacerequest is provisioned with namespace access and no secretRef
  • the subspace is ready with the given tiername from the spacerequest

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
8.9% 8.9% Duplication

@openshift-merge-robot
Copy link

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Merging #902 (0cd9550) into master (41c56bb) will increase coverage by 0.11%.
Report is 3 commits behind head on master.
The diff coverage is 92.59%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #902      +/-   ##
==========================================
+ Coverage   83.70%   83.81%   +0.11%     
==========================================
  Files          53       53              
  Lines        6178     6183       +5     
==========================================
+ Hits         5171     5182      +11     
+ Misses        822      818       -4     
+ Partials      185      183       -2     
Files Coverage Δ
...ontrollers/spacerequest/spacerequest_controller.go 83.75% <92.59%> (+1.34%) ⬆️

... and 1 file with indirect coverage changes

@mfrancisc
Copy link
Contributor

@Kartikey-star since you were assigned to work on new effort, I took the liberty to fetch the changes from your PR here and open a new PR #972 which has:

  • rebase with master
  • fix the conflicts
  • add the remaining changes

I'll work on doing the same for the toolchain-e2e tests PR
I hope you don't mind. Thanks a lot for your help here and great work!

@mfrancisc mfrancisc closed this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants