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

feat: create tiertemplaterevision for each tiertemplate #1061

Open
wants to merge 33 commits into
base: master
Choose a base branch
from

Conversation

mfrancisc
Copy link
Contributor

@mfrancisc mfrancisc commented Nov 12, 2024

E2e tests for: codeready-toolchain/host-operator#1103

  • verifies that when creating a TierTemplate with the TemplateObjects field populated it triggers the creation of a TierTemplateRevision CR as well
  • verify owner reference of the TTR
  • verify labels are set correctly on the TTR

Jira: https://issues.redhat.com/browse/KUBESAW-146

# Conflicts:
#	testsupport/init.go
test/e2e/parallel/nstemplatetier_test.go Show resolved Hide resolved
testsupport/wait/host.go Outdated Show resolved Hide resolved
testsupport/wait/host.go Outdated Show resolved Hide resolved
testsupport/wait/host.go Outdated Show resolved Hide resolved
test/e2e/parallel/nstemplatetier_test.go Outdated Show resolved Hide resolved
@mfrancisc
Copy link
Contributor Author

seems like some infra/flaky issue:

  proxy_test.go:385: 
        	Error Trace:	/go/src/github.com/codeready-toolchain/toolchain-e2e/test/e2e/parallel/proxy_test.go:385
        	Error:      	Received unexpected error:
        	            	configmaps "kube-root-ca.crt" not found

https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/test-platform-results/pr-logs/pull/codeready-toolchain_toolchain-e2e/1061/pull-ci-codeready-toolchain-toolchain-e2e-master-e2e/1859128319136501760/build-log.txt

@mfrancisc
Copy link
Contributor Author

/retest

@mfrancisc
Copy link
Contributor Author

infra issues:

WARNING: timed out waiting for git server, will wait 1m4s
error: fatal: unable to access 'https://github.com/codeready-toolchain/toolchain-e2e.git/': Could not resolve host: github.com

/retest

Copy link
Contributor

@rsoaresd rsoaresd left a comment

Choose a reason for hiding this comment

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

Good job! 🚀 Just a minor question:

testsupport/wait/host.go Outdated Show resolved Hide resolved
@mfrancisc
Copy link
Contributor Author

@mfrancisc
Copy link
Contributor Author

/retest

Copy link

openshift-ci bot commented Dec 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: metlos, mfrancisc

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

The pull request process is described 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

Comment on lines +427 to +430
namespaceResourcesWithTemplateObjects := tiers.WithNamespaceResources(t, baseTier, updateTierTemplateObjects)
clusterResourcesWithTemplateObjects := tiers.WithClusterResources(t, baseTier, updateTierTemplateObjects)
spaceRolesWithTemplateObjects := tiers.WithSpaceRoles(t, baseTier, updateTierTemplateObjects)
tiers.CreateCustomNSTemplateTier(t, hostAwait, "ttr", baseTier, namespaceResourcesWithTemplateObjects, clusterResourcesWithTemplateObjects, spaceRolesWithTemplateObjects, tiers.WithParameter("DEPLOYMENT_QUOTA", "60"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

easier to read:

Suggested change
namespaceResourcesWithTemplateObjects := tiers.WithNamespaceResources(t, baseTier, updateTierTemplateObjects)
clusterResourcesWithTemplateObjects := tiers.WithClusterResources(t, baseTier, updateTierTemplateObjects)
spaceRolesWithTemplateObjects := tiers.WithSpaceRoles(t, baseTier, updateTierTemplateObjects)
tiers.CreateCustomNSTemplateTier(t, hostAwait, "ttr", baseTier, namespaceResourcesWithTemplateObjects, clusterResourcesWithTemplateObjects, spaceRolesWithTemplateObjects, tiers.WithParameter("DEPLOYMENT_QUOTA", "60"))
tiers.CreateCustomNSTemplateTier(t, hostAwait, "ttr", baseTier,
tiers.WithNamespaceResources(t, baseTier, updateTierTemplateObjects),
tiers.WithClusterResources(t, baseTier, updateTierTemplateObjects),
tiers.WithSpaceRoles(t, baseTier, updateTierTemplateObjects),
tiers.WithParameter("DEPLOYMENT_QUOTA", "60"))

Copy link
Collaborator

Choose a reason for hiding this comment

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

and btw, the CRQ logically doesn't make much sense for the namespace-scoped templates (which is namespace and spaceRole templates) but I understand that this is only for the testing purposes.
Let's maybe make a comment and make cure that we don't try to provision a user with it.

Comment on lines +435 to +439
customTier, err := hostAwait.WaitForNSTemplateTierAndCheckTemplates(t, "ttr", wait.HasStatusTierTemplateRevisions([]string{
fmt.Sprintf("ttrfrom%s", baseTier.Spec.Namespaces[0].TemplateRef), // check that the revision field is set using the expected tierTemplate refs as keys
fmt.Sprintf("ttrfrom%s", baseTier.Spec.SpaceRoles["admin"].TemplateRef), // we can safely use the template refs from base tier since the custom tier was created from base one.
fmt.Sprintf("ttrfrom%s", baseTier.Spec.ClusterResources.TemplateRef),
}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

why not using tiers.GetTemplateRefs(t, hostAwait, "ttr").Flatten()? Wouldn't it have the same result?

Suggested change
customTier, err := hostAwait.WaitForNSTemplateTierAndCheckTemplates(t, "ttr", wait.HasStatusTierTemplateRevisions([]string{
fmt.Sprintf("ttrfrom%s", baseTier.Spec.Namespaces[0].TemplateRef), // check that the revision field is set using the expected tierTemplate refs as keys
fmt.Sprintf("ttrfrom%s", baseTier.Spec.SpaceRoles["admin"].TemplateRef), // we can safely use the template refs from base tier since the custom tier was created from base one.
fmt.Sprintf("ttrfrom%s", baseTier.Spec.ClusterResources.TemplateRef),
}))
customTier, err := hostAwait.WaitForNSTemplateTierAndCheckTemplates(t, "ttr", wait.HasStatusTierTemplateRevisions([]string{
fmt.Sprintf("ttrfrom%s", baseTier.Spec.Namespaces[0].TemplateRef), // check that the revision field is set using the expected tierTemplate refs as keys
customTier, err := hostAwait.WaitForNSTemplateTierAndCheckTemplates(t, "ttr",
wait.HasStatusTierTemplateRevisions(tiers.GetTemplateRefs(t, hostAwait, "ttr").Flatten()))

// But since the creation of a TTR could be very quick and could trigger another reconcile of the NSTemplateTier before the status is actually updated with the reference,
// this might generate some copies of the TTRs. This is not a problem in production since the cleanup mechanism of TTRs will remove the extra ones but could cause some flakiness with the test,
// thus we assert the number of TTRs doesn't exceed the double of the expected number.
assert.LessOrEqual(t, len(objs.Items), 6)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess that you can also use the len of TemplateRef from tiers.GetTemplateRefs(t, hostAwait, "ttr").Flatten(), right?
Just in case the number of templateRefs changes in the base1ns tier

Comment on lines +464 to +465
assert.Equal(t, obj.Spec.Parameters[0].Name, customTier.Spec.Parameters[0].Name)
assert.Equal(t, obj.Spec.Parameters[0].Value, customTier.Spec.Parameters[0].Value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

the same as in the other PR:

Suggested change
assert.Equal(t, obj.Spec.Parameters[0].Name, customTier.Spec.Parameters[0].Name)
assert.Equal(t, obj.Spec.Parameters[0].Value, customTier.Spec.Parameters[0].Value)
assert.ElementsMatch(t, customTier.Spec.Parameters, obj.Spec.Parameters)

Comment on lines +268 to +278
for i := range ttrs.Items {
ttr := ttrs.Items[i]
c.t.Logf("deleting also the related TTR %s", ttr.GetName())
if err := c.client.Delete(context.TODO(), &ttr, propagationPolicyOpts); err != nil {
if errors.IsNotFound(err) {
continue
}
c.t.Logf("problem with deleting the related TTR %s: %s", ttr.GetName(), err)
return false, err
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can simplify this by calling DeleteAllOf

Suggested change
for i := range ttrs.Items {
ttr := ttrs.Items[i]
c.t.Logf("deleting also the related TTR %s", ttr.GetName())
if err := c.client.Delete(context.TODO(), &ttr, propagationPolicyOpts); err != nil {
if errors.IsNotFound(err) {
continue
}
c.t.Logf("problem with deleting the related TTR %s: %s", ttr.GetName(), err)
return false, err
}
}
return false, c.client.DeleteAllOf(context.TODO(), &toolchainv1alpha1.TierTemplateRevision{},
client.InNamespace(nsTemplateTier.GetNamespace()),
client.MatchingLabels{toolchainv1alpha1.TierLabelKey: nsTemplateTier.GetName()})

Comment on lines +279 to +283
} else if len(ttrs.Items) > 0 {
// ttrs are still there
return false, nil
}
return true, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

if the ttr.Items is empty, then the method returns a few lines earlier

Suggested change
} else if len(ttrs.Items) > 0 {
// ttrs are still there
return false, nil
}
return true, nil
}
// ttrs are still there
return false, nil

Comment on lines +927 to +928
if tierTemplateNamespaces.Spec.TemplateObjects != nil {
ttrName, found := tier.Status.Revisions[tierTemplateNamespaces.GetName()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

this technically expects that if the TierTemplate of the NSTemplateTier supports the new way of defining templates, then the function WaitForNSTemplateTierAndCheckTemplates has to be called with wait.HasStatusTierTemplateRevisions; otherwise, it may result with flakiness.
it's fine for now, but it has to be changed/improved in the future

if !found {
return nil, fmt.Errorf("missing revision for TierTemplate %s in NSTemplateTier '%s'", tierTemplateNamespaces.GetName(), tier.Name)
}
if _, err := a.WaitForTierTemplateRevision(t, ttrName); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess that you can use simply

Suggested change
if _, err := a.WaitForTierTemplateRevision(t, ttrName); err != nil {
if _, err := For(t, a.Awaitility, &toolchainv1alpha1.TierTemplateRevision{}).WithNameThat(ttrName); err != nil {

and drop completely the WaitForTierTemplateRevision function.

Comment on lines +945 to +954
// if the tier template supports Tier Template Revisions then let's check those
if tierTemplateClusterResources.Spec.TemplateObjects != nil {
ttrName, found := tier.Status.Revisions[tierTemplateClusterResources.GetName()]
if !found {
return nil, fmt.Errorf("missing revision for TierTemplate %s in NSTemplateTier '%s'", tierTemplateClusterResources.GetName(), tier.Name)
}
if _, err := a.WaitForTierTemplateRevision(t, ttrName); err != nil {
return nil, err
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this code looks like the same as previous one - why not moving it to a separate method:

func (a *HostAwaitility) checkTTR(t *testing.T, tier *toolchainv1alpha1.NSTemplateTier, tierTemplate *toolchainv1alpha1.TierTemplate) error {
	// if the tier template supports Tier Template Revisions then let's check those
	if tierTemplate.Spec.TemplateObjects != nil {
		ttrName, found := tier.Status.Revisions[tierTemplate.GetName()]
		if !found {
			return fmt.Errorf("missing revision for TierTemplate %s in NSTemplateTier '%s'", tierTemplate.GetName(), tier.Name)
		}
		if _, err := For(t, a.Awaitility, &toolchainv1alpha1.TierTemplateRevision{}).WithNameThat(ttrName); err != nil {
			return err
		}
	}
	return nil
}

so you can then call

if err := a.checkTTR(t, tier, tierTemplateClusterResources); err != nil {
	return nil, err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants