Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Fix context UI add formatting refactor #57

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

Conversation

chanwit
Copy link
Contributor

@chanwit chanwit commented Sep 9, 2021

This PR

  • fixed K8s context listing bug
  • added code formatting for TypeScript and Go, including ESLit and Go Vet
  • did some refactoring
  • updated CRDs to those of Flux v0.17.0

Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
@squaremo
Copy link
Member

squaremo commented Sep 9, 2021

Thanks @chanwit! Would you please split this into PRs that accomplish one thing (or near enough) -- maybe

  • put formatting and linting in the build
  • fix bug and refactoring (if the refactoring pertains to the code you were fixing)
  • update the CRDs (unless that is part of fixing, or refactoring)

@chanwit chanwit mentioned this pull request Sep 9, 2021
Copy link
Collaborator

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

@chanwit Can you describe the bug this is trying to fix?

@@ -4,7 +4,8 @@
"plugin:import/errors",
"plugin:import/warnings",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript"
"plugin:import/typescript",
"plugin:prettier/recommended" // eslint shows prettier formatting warnings. Must be always the last configuration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This may cause conflicts with typescript. Having two formmatters running will cause them to over-write each others' changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not very good at this kind of configuration.

Did you mean that we could just use eslint --fix and the source would get formatted without using prettier? If so, I'm happy to remove it.

const { navigate, currentPage } = useNavigation();

const contextSelectChanged = (ev) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this moved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Embedding event handlers into the view is too hard to read.

@@ -1,38 +1,46 @@

export interface TwirpErrorJSON {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a generated file. When make proto is run, this formatting will be over-written.


all: test build
all: dist/index.html fmt vet test build
Copy link
Collaborator

Choose a reason for hiding this comment

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

We probably shouldn't do "write" operations (formatting) on the make all commands. I wouldn't expect a make all command to leave us with a (potentially) modified git state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We did that in Flux CLI. Go Fmt is part of the make file. Should we do this @stefanprodan?

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Jordan here; I think it's OK to have phony targets that rewrite files, but the main build shouldn't create (more) diffs. If it does, it encourages commits which contain code changes then some random reformatting elsewhere.

This can make it difficult to reconcile with builds in which you commit generated files. For that, you can make people explicitly regenerate the file, and have a guard in the tests (and CI) to make sure the committed, generated file is correct.

(Also see go build -mod=readonly.)

Copy link
Member

Choose a reason for hiding this comment

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

(You can call me a hypocrite, since all the flux controllers inherit a Makefile structure which does fmt in the build, from kubebuilder. I don't notice because I've told emacs to run go fmt when I save a file.)

for _, c := range rules.Contexts {
contexts = append(contexts, c.Cluster)
for contextName := range rules.Contexts {
contexts = append(contexts, contextName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We were accessing c.Cluster before. Do we no longer need to do that?

@@ -1,39 +1,32 @@
// Code generated by protoc-gen-twirp v7.1.1, DO NOT EDIT.
Copy link
Collaborator

@jpellizzari jpellizzari Sep 9, 2021

Choose a reason for hiding this comment

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

I would not have expected this file to change. We probably need to use buf instead to avoid this happening in the future. Not something that needs to be taken care of by this PR, but we should probably revert this change for now.

@@ -0,0 +1,223 @@
#!/usr/bin/env bash
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should have users manage their own installation. In addition, anyone who downloads the binary won't have this script, and if they have cloned the repo, they are probably intending to build from source.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a plan to have a brew/tap, yes.


dist/index.html:
npm run build

fmt:
go fmt ./...
npx prettier --write 'ui/**/*.ts(x)?'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think one formatter is the way to go here. Two formatters may end up conflicting with one another.

@chanwit
Copy link
Contributor Author

chanwit commented Sep 9, 2021

@jpellizzari I am in process of splitting this PR into smaller ones as @squaremo pointed out.

For the bug fixing part, there's a bug when we obtaining the list of contexts. Please see its structure and you'll see that we used the wrong field, c.Cluster.
c.Cluster is the cluster name, but not the context name.
The context name appears to be the key portion of rules.Contexts map.
I found this bug accidentally because a cluster name and a context on my machine are different.

@jpellizzari
Copy link
Collaborator

@jpellizzari I am in process of splitting this PR into smaller ones as @squaremo pointed out.

For the bug fixing part, there's a bug when we obtaining the list of contexts. Please see its structure and you'll see that we used the wrong field, c.Cluster.
c.Cluster is the cluster name, but not the context name.
The context name appears to be the key portion of rules.Contexts map.
I found this bug accidentally because a cluster name and a context on my machine are different.

Excellent! Nice find. I will await those PRs; feel free to add me as a reviewer when they are ready. Thanks for the contribution.

@squaremo
Copy link
Member

squaremo commented Sep 9, 2021

we used the wrong field, c.Cluster.
c.Cluster is the cluster name, but not the context name.
The context name appears to be the key portion of rules.Contexts map.

Please be sure to put this explanation in the commit message :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants