-
Notifications
You must be signed in to change notification settings - Fork 73
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
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # testsupport/init.go
seems like some infra/flaky issue:
|
/retest |
infra issues:
/retest |
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.
Good job! 🚀 Just a minor question:
/retest user management test failure: 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/1861390378251325440/build-log.txt looking into it to see if it's flaky |
/retest |
[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 |
Quality Gate passedIssues Measures |
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")) |
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.
easier to read:
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")) |
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.
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.
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), | ||
})) |
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.
why not using tiers.GetTemplateRefs(t, hostAwait, "ttr").Flatten()
? Wouldn't it have the same result?
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) |
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.
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
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) |
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.
the same as in the other PR:
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) |
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 | ||
} | ||
} |
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.
you can simplify this by calling DeleteAllOf
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()}) |
} else if len(ttrs.Items) > 0 { | ||
// ttrs are still there | ||
return false, nil | ||
} | ||
return true, nil |
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.
if the ttr.Items is empty, then the method returns a few lines earlier
} else if len(ttrs.Items) > 0 { | |
// ttrs are still there | |
return false, nil | |
} | |
return true, nil | |
} | |
// ttrs are still there | |
return false, nil |
if tierTemplateNamespaces.Spec.TemplateObjects != nil { | ||
ttrName, found := tier.Status.Revisions[tierTemplateNamespaces.GetName()] |
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.
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 { |
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.
I guess that you can use simply
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.
// 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 | ||
} | ||
} |
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.
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
}
E2e tests for: codeready-toolchain/host-operator#1103
Jira: https://issues.redhat.com/browse/KUBESAW-146