Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

feat(validation): Add catalog entry validation in controller #5

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

varshaprasad96
Copy link
Contributor

@varshaprasad96 varshaprasad96 commented Aug 31, 2022

  1. Validate export references in entry spec
  2. Aggregate PermissionClaims and API resources info from
    referenced APIExport to entry status

Signed-off-by: Vu Dinh [email protected]

@varshaprasad96
Copy link
Contributor Author

This is based on the CE api defined in commit (6f259d6) and is subject to change. Please hold from reviewing as this is not complete yet.
/hold

@varshaprasad96 varshaprasad96 added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 31, 2022
@ncdc
Copy link
Member

ncdc commented Sep 13, 2022

If you don't mind, please pause working on this until we have solidified the API. Thanks!

@dinhxuanvu dinhxuanvu changed the title WIP: Hack/catalog controller [WIP]: feat(validation): Add catalog entry validation in controller Sep 28, 2022
@dinhxuanvu dinhxuanvu changed the title [WIP]: feat(validation): Add catalog entry validation in controller [WIP] feat(validation): Add catalog entry validation in controller Sep 28, 2022
@varshaprasad96 varshaprasad96 mentioned this pull request Oct 11, 2022
5 tasks
@dinhxuanvu dinhxuanvu force-pushed the hack/cotalog-controller branch 3 times, most recently from b488298 to 0b17ed1 Compare October 18, 2022 20:26
@dinhxuanvu dinhxuanvu marked this pull request as ready for review October 18, 2022 20:27
@dinhxuanvu dinhxuanvu changed the title [WIP] feat(validation): Add catalog entry validation in controller feat(validation): Add catalog entry validation in controller Nov 10, 2022
@dinhxuanvu dinhxuanvu removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 10, 2022
varshaprasad96 and others added 2 commits November 10, 2022 20:06
1. Validate export references in entry spec
2. Aggregate PermissionClaims and API resources info from
referenced APIExport to entry status

Signed-off-by: Vu Dinh <[email protected]>
Signed-off-by: Vu Dinh <[email protected]>
exportPermissionClaims := []apisv1alpha1.PermissionClaim{}
invalidExports := []string{}
for _, exportRef := range catalogEntry.Spec.Exports {
// TODO: verify if path contains the entire heirarchy or just the clusterName.
Copy link
Member

Choose a reason for hiding this comment

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

Path should be the full hierachy/absolute path

)
logger.V(2).Info("reconciling CatalogEntry")
export := apisv1alpha1.APIExport{}
err := r.Get(logicalcluster.WithCluster(ctx, logicalcluster.New(path)), types.NamespacedName{Name: name, Namespace: req.Namespace}, &export)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := r.Get(logicalcluster.WithCluster(ctx, logicalcluster.New(path)), types.NamespacedName{Name: name, Namespace: req.Namespace}, &export)
err := r.Get(logicalcluster.WithCluster(ctx, logicalcluster.New(path)), types.NamespacedName{Name: name}, &export)

Copy link
Member

Choose a reason for hiding this comment

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

APIExports are cluster-scoped

Comment on lines +113 to +115
// Error reading the object - requeue the request.
logger.Error(err, "failed to get resource")
continue
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't actually requeue like the comment says

Comment on lines +139 to +145
cond := conditionsapi.Condition{
Type: catalogv1alpha1.APIExportValidType,
Status: corev1.ConditionTrue,
Severity: conditionsapi.ConditionSeverityNone,
LastTransitionTime: metav1.Now(),
}
conditions.Set(catalogEntry, &cond)
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use conditions.MarkTrue() here

Comment on lines +147 to +155
message := fmt.Sprintf("invalid export(s): %s", strings.Join(invalidExports, " ,"))
invalidCond := conditionsapi.Condition{
Type: catalogv1alpha1.APIExportValidType,
Status: corev1.ConditionFalse,
Severity: conditionsapi.ConditionSeverityError,
LastTransitionTime: metav1.Now(),
Message: message,
}
conditions.Set(catalogEntry, &invalidCond)
Copy link
Member

Choose a reason for hiding this comment

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

You should be able to use conditions.MarkFalse() here

return nil, fmt.Errorf("could not create CatalogEntry %q|%q: %v", workspaceCluster, entryName, err)
}

t.Logf("waiting for CatalogEntry %q|%q to be found", workspaceCluster, entryName)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
t.Logf("waiting for CatalogEntry %q|%q to be found", workspaceCluster, entryName)
t.Logf("waiting for CatalogEntry %q|%q to have APIExportValid condition", workspaceCluster, entryName)

}
return true, nil
}); err != nil {
return nil, fmt.Errorf("CatalogEntry %q|%q not found: %v", workspaceCluster, entryName, err)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("CatalogEntry %q|%q not found: %v", workspaceCluster, entryName, err)
return nil, fmt.Errorf("error waiting for CatalogEntry %q|%q status: %v", workspaceCluster, entryName, err)


t.Logf("waiting for CatalogEntry %q|%q to be found", workspaceCluster, entryName)
var catalogEntry catalogv1alpha1.CatalogEntry
if err := wait.PollImmediate(100*time.Millisecond, wait.ForeverTestTimeout, func() (done bool, err error) {
Copy link
Member

Choose a reason for hiding this comment

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

I would move this into the Test() functions themselves

if err != nil {
t.Fatalf("unable to create CatalogEntry: %v", err)
}

Copy link
Member

Choose a reason for hiding this comment

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

Insert polling loop to get entry and expect conditions.IsTrue(entry, catalogv1alpha1.APIExportValidType)

if err != nil {
t.Fatalf("catalogEntry %q failed to be reconciled in cluster %q: %v", entry.GetName(), workspaceCluster, err)
}

Copy link
Member

Choose a reason for hiding this comment

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

Insert polling loop

@openshift-merge-robot
Copy link
Contributor

@varshaprasad96: 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.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants