-
Notifications
You must be signed in to change notification settings - Fork 2
feat(validation): Add catalog entry validation in controller #5
base: main
Are you sure you want to change the base?
feat(validation): Add catalog entry validation in controller #5
Conversation
|
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. |
|
If you don't mind, please pause working on this until we have solidified the API. Thanks! |
106c7b4 to
7ee76a1
Compare
5215e6b to
0af5f63
Compare
b488298 to
0b17ed1
Compare
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 <vudinh@outlook.com>
0b17ed1 to
a953022
Compare
Signed-off-by: Vu Dinh <vudinh@outlook.com>
a953022 to
70824d8
Compare
Signed-off-by: Vu Dinh <vudinh@outlook.com>
1f2341d to
6e38f56
Compare
Signed-off-by: Vu Dinh <vudinh@outlook.com>
Signed-off-by: Vu Dinh <vudinh@outlook.com>
Signed-off-by: Vu Dinh <vudinh@outlook.com>
Signed-off-by: Vu Dinh <vudinh@outlook.com>
Signed-off-by: Vu Dinh <vudinh@outlook.com>
| exportPermissionClaims := []apisv1alpha1.PermissionClaim{} | ||
| invalidExports := []string{} | ||
| for _, exportRef := range catalogEntry.Spec.Exports { | ||
| // TODO: verify if path contains the entire heirarchy or just the clusterName. |
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.
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) |
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.
| 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) |
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.
APIExports are cluster-scoped
| // Error reading the object - requeue the request. | ||
| logger.Error(err, "failed to get resource") | ||
| continue |
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 doesn't actually requeue like the comment says
| cond := conditionsapi.Condition{ | ||
| Type: catalogv1alpha1.APIExportValidType, | ||
| Status: corev1.ConditionTrue, | ||
| Severity: conditionsapi.ConditionSeverityNone, | ||
| LastTransitionTime: metav1.Now(), | ||
| } | ||
| conditions.Set(catalogEntry, &cond) |
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 should be able to use conditions.MarkTrue() here
| 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) |
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 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) |
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.
| 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) |
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.
| 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) { |
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 would move this into the Test() functions themselves
| if err != nil { | ||
| t.Fatalf("unable to create CatalogEntry: %v", 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.
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) | ||
| } | ||
|
|
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.
Insert polling loop
|
@varshaprasad96: PR needs rebase. DetailsInstructions 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. |
referenced APIExport to entry status
Signed-off-by: Vu Dinh vudinh@outlook.com