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

Extend explorer - Templates #3358

Merged
merged 10 commits into from
Sep 26, 2023
Merged

Extend explorer - Templates #3358

merged 10 commits into from
Sep 26, 2023

Conversation

ranatrk
Copy link
Contributor

@ranatrk ranatrk commented Sep 14, 2023

Closes #2957

What changed?
Add capiTemplates and gitopsTemplates to explorer filters
Screenshot from 2023-09-17 13-22-27

Why was this change made?
Extending the explorer to be compatible to filter based on the kind CapiTemplates and GitOpsTemplates

How was this change implemented?
Add both templates to compatible objects used in the explorer filter
Returning no status when getting flux object to show no status in the ui

How did you validate the change?

  • Explain how a reviewer can verify the change themselves
    manual test: Add a template(capi or gitops), then through the explorer view tab, enable the filter to only show that template type

Release notes
Add templates,Capi and GitOps, to explorer filters

Documentation Changes
N/A

Other follow ups

@ranatrk ranatrk added the enhancement New feature or request label Sep 14, 2023
@ranatrk ranatrk force-pushed the extend-explorer-templates branch 2 times, most recently from 0c3cc5b to a302b9a Compare September 17, 2023 10:54
@ranatrk ranatrk marked this pull request as ready for review September 17, 2023 11:26
@ranatrk
Copy link
Contributor Author

ranatrk commented Sep 17, 2023

the current state in this PR is that templates will direct to the main templates page, where each template doesn't have a details page. There is also another option that I can remove the redirect so the yaml of the templates show in the explorer details rather than directing to the /templates endpoint.
@enekofb wdyt?

@enekofb enekofb requested a review from a team September 18, 2023 07:05
@enekofb
Copy link
Contributor

enekofb commented Sep 18, 2023

There is also another option that I can remove the redirect so the yaml of the templates show in the explorer details rather than directing to the /templates endpoint.

As a user, once you have found something in explorer you click to be able to do somethingelse with the found resource, i could think that in the context of templates is going to the templates page over the unstructured yaml (it does not allow the user to do another action than view raw data).

A third option (that you could consider) is to redirect to Templates view with focus in the selected template by using a URL that searches by the name of the template. Something like this

Given explorer with a template aws-eks-dev
When i select the template
Then templates view is opened with the template as the search result
So the user can view more specific details for he resource of interest and act on it (use the template)

Screenshot 2023-09-18 at 09 23 57

Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

Reviewed the code with some suggestions. Not yet tested as some of the suggestions could change how the feature behaves.

},
AddToSchemeFunc: gapiv1.AddToScheme,
StatusFunc: func(obj client.Object) ObjectStatus {
e, ok := obj.(*corev1.Event)
Copy link
Contributor

Choose a reason for hiding this comment

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

given obj represents this interface which is a generic kube object, and you will use this function for templates, then the casting to Event on this line would always fail.

If you don't expect a status different to NoStatus, you could just return it directly without any other logic for this function.

return Failed
},
MessageFunc: func(obj client.Object) string {
e, ok := obj.(*corev1.Event)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as mentioned for StatusFunc. Here you could consider whether you want to use this field for giving another type of information to the user in a simplified manner to help them select: I could think that an option could be to return the description if that suits you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looking at the templates object, the description is probably the only item that could be used. But would it be confusing to the user to have some messages indicating the status message as actions while the templates have a description
action format example : Release reconciliation succeeded
description format example: Add a Helm Repository to all clusters

return &capiv1.CAPITemplate{}
},
AddToSchemeFunc: capiv1.AddToScheme,
StatusFunc: func(obj client.Object) ObjectStatus {
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as for GitopsTemplate

return Failed
},
MessageFunc: func(obj client.Object) string {
e, ok := obj.(*corev1.Event)
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as for GitopsTemplate

@@ -263,6 +326,9 @@ func defaultFluxObjectStatusFunc(obj client.Object) ObjectStatus {
if err != nil {
return Failed
}
if fo == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

do you still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, it's replaced with the custom status and message functions

@@ -99,6 +101,16 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatalf("add GitopsSet to schema failed: %s", err)
}

err = gapiv1.AddToScheme(scheme.Scheme)
Copy link
Contributor

Choose a reason for hiding this comment

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

you might want also to add a test case (as you did for gitopssets) for template resources

@ranatrk
Copy link
Contributor Author

ranatrk commented Sep 18, 2023

A third option (that you could consider) is to redirect to Templates view with focus in the selected template by using a URL that searches by the name of the template. Something like this

Given explorer with a template aws-eks-dev When i select the template Then templates view is opened with the template as the search result So the user can view more specific details for he resource of interest and act on it (use the template)

that's a nice idea, I'll look into the templates FE code to see it's feasibility

Copy link

@jpellizzari jpellizzari left a comment

Choose a reason for hiding this comment

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

Code LGTM! Let us know if we need to update our extending-explorer.md README with any new information.

@ranatrk
Copy link
Contributor Author

ranatrk commented Sep 19, 2023

current state:

  • Custom adapters are created for the template objects to be considered as fluxObjects with GetConditions function.
  • The objects being cast in the custom MessageFunc are the adapters and not GitOpsTemplate and CAPITemplate objects

@foot
Copy link
Collaborator

foot commented Sep 20, 2023

Thanks @ranatrk! We were looking at the code and wondering if we could remove the explicit call to ToFluxObject inside of GetStatus and GetMessage?

func (n defaultNormalizedObject) GetStatus() (configuration.ObjectStatus, error) {
o, err := configuration.ToFluxObject(n.Object)
if err != nil {
return "", err
}
return n.config.StatusFunc(o), nil
}
func (n defaultNormalizedObject) GetMessage() (string, error) {
o, err := configuration.ToFluxObject(n.Object)
if err != nil {
return "", err
}
return n.config.MessageFunc(o), nil
}

This would mean ToFluxObject would only be called in the defaultFluxObjectStatusFunc / defaultFluxObjectMessageFunc and wouldn't have to worry about handling types other than flux ones.

func defaultFluxObjectStatusFunc(obj client.Object) ObjectStatus {
fo, err := ToFluxObject(obj)

cc @enekofb does that make sense? There might be extra context.

@enekofb
Copy link
Contributor

enekofb commented Sep 21, 2023

Thanks @ranatrk! We were looking at the code and wondering if we could remove the explicit call to ToFluxObject inside of GetStatus and GetMessage?

func (n defaultNormalizedObject) GetStatus() (configuration.ObjectStatus, error) {
o, err := configuration.ToFluxObject(n.Object)
if err != nil {
return "", err
}
return n.config.StatusFunc(o), nil
}
func (n defaultNormalizedObject) GetMessage() (string, error) {
o, err := configuration.ToFluxObject(n.Object)
if err != nil {
return "", err
}
return n.config.MessageFunc(o), nil
}

This would mean ToFluxObject would only be called in the defaultFluxObjectStatusFunc / defaultFluxObjectMessageFunc and wouldn't have to worry about handling types other than flux ones.

func defaultFluxObjectStatusFunc(obj client.Object) ObjectStatus {
fo, err := ToFluxObject(obj)

cc @enekofb does that make sense? There might be extra context.

@foot definitely, it needs decoupling ...

raising a PR, should be soon

@enekofb
Copy link
Contributor

enekofb commented Sep 21, 2023

raised PR for the toFluxObject mandate

@enekofb
Copy link
Contributor

enekofb commented Sep 25, 2023

PR merged, please rebase

@ranatrk
Copy link
Contributor Author

ranatrk commented Sep 25, 2023

thanks @enekofb for the updates in the toFluxObject. I rebased and did a minor change in the url for the redirection to templates page

Copy link
Contributor

@enekofb enekofb left a comment

Choose a reason for hiding this comment

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

Great job!

Tested that I could see templates and navigate to them correctly:

Screenshot 2023-09-25 at 18 23 15

Suggest to follow up adding it to the user documentation (rather small change)

@ranatrk ranatrk merged commit 9f7c41e into main Sep 26, 2023
10 checks passed
@ranatrk ranatrk deleted the extend-explorer-templates branch September 26, 2023 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch Cluster/Template/Gitopsset etc querying to the explorer querier
4 participants