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

Make it easy to find out the k8s and flux version #2349

Merged
merged 13 commits into from
Jun 29, 2022

Conversation

opudrovs
Copy link
Contributor

@opudrovs opudrovs commented Jun 21, 2022

Closes #2285
Closes #2328

  • I've added a namespace to the GetVersionRequest object to make TestGetVersion pass because it could not find the flux-system namespace without it. So, for the test I create a new namespace or if the namespace is not provided default to flux-system (wego.DefaultNamespace constant). If anyone knows how to improve this and the issue with nested ifs (will add a comment), I'm all ears. 🙂

UPDATE: Removed the namespace field from GetVersionRequest (switched to listing namespaces) and fixed nested ifs based on @ozamosi 's suggestions.

  • I've copy-pasted the test for GetImpersonatedDiscoveryClient from the test for GetImpersonatedClient. I am not sure what this API does and what exactly should be tested, maybe it should be modified.

Also removed the following from the copied test, maybe it should be put back (this part was failing because the number of found namespaces in the copy-pasted part was 0 instead of 1 or 2):

t.Run("checks all namespaces in the cluster when through the filtering", func(t *testing.T) {
	g.Expect(nsChecker.FilterAccessibleNamespacesCallCount()).To(Equal(1))

	_, _, nss := nsChecker.FilterAccessibleNamespacesArgsForCall(0)
	nsFound := 0
	for _, n := range nss {
		if n.Name == ns1.Name || n.Name == ns2.Name {
			nsFound++
		}
	}

	g.Expect(nsFound).To(Equal(2))
})

@opudrovs opudrovs added type/enhancement New feature or request team/denim labels Jun 21, 2022
@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch 10 times, most recently from ebe2afe to f81f64f Compare June 23, 2022 13:58
fluxVersion = u.GetLabels()["app.kubernetes.io/version"]
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ozamosi @chanwit suggestions on how to simplify nested ifs here (looks similar to a "callback hell" in JS) welcome!

I don't want to return nil from GetVersion on error when getting additional values, because I want to display at least available values (at least the values set at the build time) in the app for debug purposes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe lift this bit into a new function, return an error from there any time there's an error, and then this function only has one error to check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good idea, will do it.

@opudrovs opudrovs marked this pull request as ready for review June 24, 2022 12:48
@opudrovs opudrovs requested review from chanwit and ozamosi June 24, 2022 12:48
@opudrovs
Copy link
Contributor Author

@ozamosi @chanwit also, maybe I can use the VersionLabelKey from the flux.go instead of app.kubernetes.io/version to get the label value?


key := client.ObjectKey{
Name: ns,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So, you're right that this can be pretty much any namespace - but I'm not sure the frontend knows what namespace to use 🤔

What if instead of Geting a specific namespace, we List filtered by {"app.kuberenetes.io/part-of": "flux"} and just grab the first result we find? After a bit of grepping - I think this helper does the filtering? https://github.com/weaveworks/weave-gitops/blob/main/core/server/server.go#L86

Copy link
Contributor Author

@opudrovs opudrovs Jun 24, 2022

Choose a reason for hiding this comment

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

OK, can do it.

From frontend we don't provide any namespace. This param was added just for passing the test (because when running the test it could not find the "flux-system" namespace). If the namespace is not provided (like when we make the request via the API, {} with no args), we just default to "flux-system" (and while the app is running normally, the "flux-system" namespace is found). At least that was the idea. 🙂

I need to see if the list function will return the flux-system/flux-whatever namespace while running the test.

@ozamosi
Copy link
Contributor

ozamosi commented Jun 24, 2022

@ozamosi @chanwit also, maybe I can use the VersionLabelKey from the flux.go instead of app.kubernetes.io/version to get the label value?

Sounds good!

if err != nil {
return defaultVersion, fmt.Errorf("error getting object: %w", err)
} else {
return u.GetLabels()["app.kubernetes.io/version"], nil
Copy link
Member

Choose a reason for hiding this comment

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

u.GetLabels() may return nil here.

Copy link
Member

Choose a reason for hiding this comment

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

never mind me @opudrovs, if you chose to use the VersionLabelKey instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, will keep it in mind.

@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch 2 times, most recently from 5c635c2 to e59fb72 Compare June 27, 2022 08:33
@opudrovs opudrovs requested a review from joshri June 27, 2022 08:35
@opudrovs
Copy link
Contributor Author

opudrovs commented Jun 27, 2022

@ozamosi @chanwit added grabbing a namespace from the list of namespaces. For testing, I create a new namespace with required key because the flux-ns namespace available during testing doesn't have a Flux version.

Also moved creating scoped client, getting Flux and K8s version to separate functions, based on @ozamosi 's suggestion. Should the create scoped client function's name start with create or get, preferably?

@chanwit just in case added checking for nil when getting the version from labels.

@joshri I've added displaying Flux and Kubernetes versions in the footer. Also added noWrap to the Text component and removed neutral30 color specified for some footer elements because it is already specified for the whole footer, it looks like, the elements already inherit this color from footer. If it is wrong, can move it back.

Spaced and colored elements based on the quick design in the UI ticket description to make it consistent with current styling of the Footer component. Please let me know if styling/spacing/whatever is wrong.

@opudrovs opudrovs requested review from ozamosi and chanwit June 27, 2022 08:41
@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch from f7249b3 to 871c8e2 Compare June 27, 2022 09:04
@opudrovs
Copy link
Contributor Author

opudrovs commented Jun 27, 2022

@ozamosi @chanwit 1) would it be possible to filter for Version label key with any value? Or only filtering by specific values is possible?

opts := client.MatchingLabels{
    coretypes.PartOfLabel: FluxNamespacePartOf,
    flux.VersionLabelKey: <any value>
}

Right now I am filtering labels only by coretypes.PartOfLabel: FluxNamespacePartOf, and then loop through the result and find a label which has flux.VersionLabelKey key.

  1. Is it OK to use functions result if I am also returning an error for it (in case of an error, I am returning the default version from flux and kube version functions, use the returned version as expected, and just log the error).

@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch 2 times, most recently from 155cb5e to ee45d46 Compare June 27, 2022 09:18
@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch from fdfb6a5 to 8d7324c Compare June 27, 2022 09:22
@ozamosi
Copy link
Contributor

ozamosi commented Jun 27, 2022

Should the create scoped client function's name start with create or get, preferably?

I feel Get feels more natural, since when calling the function I don't care if it's allocating a new client or reusing a cached one.

would it be possible to filter for Version label key with any value?

I've not seen that, and a quick peek doesn't reveal anything. So, maybe not?

Is it OK to use functions result if I am also returning an error for it

It's uncommon.

I prefer to think of it as, go has exceptions, it's just that they don't bubble up automatically so you have to constantly wire them up manually. So every time I see res, err := Function(); if err != nil { return err } it's just line noise that does what you get for free by calling throw Exception() in another language. As a result, if you do something that you couldn't express with "return value, or throw exception", then I have to go and review the code more carefully.

That doesn't mean it's always wrong. But in this case, if the returned value is simply an empty string, then I'd write it so that the calling function sets the default instead of the called function - so the fall-back is implemented as an "exception handler".

@opudrovs
Copy link
Contributor Author

@ozamosi OK, thank you, got it, will add the changes now.

@opudrovs
Copy link
Contributor Author

@ozamosi added the fixes.

@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch from a56b68e to 4766770 Compare June 27, 2022 15:08
Copy link
Contributor

@joshri joshri left a comment

Choose a reason for hiding this comment

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

I'm getting this back right now on the version request so nothing shows up in the page: branch: "" buildTime: "" commit: "" semver: "v0.0.0"
We might want to add a dash or something if no data comes through but the request was successful?

) : null;

const kubeVersionText = versionData.kubeVersion;
const kubeVersion =
Copy link
Contributor

Choose a reason for hiding this comment

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

fluxVersion and kubeVersion could potentially be combined into one component with props but I don't mind either way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, will do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the Version component with snapshot tests.

  1. Not sure if adding attrs when exported is still required, like recommended in the style.md doc, so still added it like that:
export default styled(Version).attrs({ className: Version.name })``;
  1. Footer versions are wrapped at narrow screens (see layout at 768 or 1000 px for example) , otherwise we would have to add a horiz scrollbar, preferably for the whole layout (or it looks ugly if added only to the footer).

Does this look OK?

Screenshot 2022-06-28 at 08 38 53

Copy link
Contributor

Choose a reason for hiding this comment

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

Three options that come to mind:

  1. Set everything to nowrap and just have it overflow the container
  2. Increase the minWidth of the container so we know we're always fitting the whole footer in
  3. Decrease font size on the footer?
    Maybe we do a mix of all three?

Copy link
Contributor Author

@opudrovs opudrovs Jun 28, 2022

Choose a reason for hiding this comment

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

Used options 1 and 2: set the Version component text to nowrap and changed 768px in Layout.tsx from to 900px (conveniently, a Material-UI breakpoints).

Everything I tried with scrollbars in the footer and footer containers looked ugly. So, I've decided not to add overflow-x: auto.

I think it's either these two applied fixes or we'd need to do a serious redesign of the footer (for example, move it under the whole app content or move content info + email text somewhere out of the footer), because the current footer text is really wide.

So, the current version looks best for now.

return (
<Flex as="footer" wide between className={className} role="footer">
<LeftFoot>
<Text color="neutral30">Need help? Contact us at</Text>
<Text>Need help? Contact us at</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

add the excellent noWrap prop here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

)}
<Spacer padding="xxs" />
<Text color="neutral30">© 2022 Weaveworks</Text>
<Text>© 2022 Weaveworks</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above - add the excellent noWrap prop!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@opudrovs
Copy link
Contributor Author

@joshri

I'm getting this back right now on the version request so nothing shows up in the page: branch: "" buildTime: "" commit: "" semver: "v0.0.0"

Did you open the app through Tilt or npm start? And are you sure you rebuilt everything and reloaded the app? Can you please try restarting Tilt?

We might want to add a dash or something if no data comes through but the request was successful?

Not a problem. Can add displaying the labels with dashes even if the Flux version and Kubernetes version are empty strings for any reason.

But there should be fields fluxVersion and kubeVersion in the network request response in any case.

Copy link
Contributor

@joshri joshri left a comment

Choose a reason for hiding this comment

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

I had to update something...classic. Rebuilt and the footer looks good!

@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch 2 times, most recently from 095f169 to 51d864d Compare June 28, 2022 14:25
@opudrovs opudrovs force-pushed the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch from 11fb4d3 to 46bf467 Compare June 29, 2022 16:17
@opudrovs opudrovs merged commit 93cd101 into main Jun 29, 2022
@opudrovs opudrovs deleted the 2285-make-it-easy-to-find-out-k8s-and-flux-version branch June 29, 2022 16:24
This was referenced Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it easy to find out the k8s and flux version - UI Make it easy to find out the k8s and flux version
4 participants