Skip to content

*: add back service account #629

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

Merged
merged 4 commits into from
Oct 17, 2018

Conversation

AlexNPavel
Copy link
Contributor

This adds service account support back to the sdk, as well as
updates some documentation and fixes the dep warning when creating
a new project

This adds service account support back to the sdk, as well as
updates some documentation and fixes the `dep` warning when creating
a new project
@AlexNPavel AlexNPavel requested review from hasbro17 and estroz October 16, 2018 21:33
@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 16, 2018
Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

LGTM

@hasbro17
Copy link
Contributor

/cc @shawn-hurley just a heads up that we'll now have a service account by default for the ansible-operator as well.

@@ -207,7 +207,9 @@ $ sed -i 's|REPLACE_IMAGE|quay.io/example/memcached-operator:v0.0.1|g' deploy/op
Deploy the memcached-operator:

```sh
$ kubectl create -f deploy/rbac.yaml
$ kubectl create -f deploy/service_account.yaml
Copy link
Member

Choose a reason for hiding this comment

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

+1 thank you for updating this file

if serviceAccountExp != buf.String() {
dmp := diffmatchpatch.New()
diffs := diffmatchpatch.New().DiffMain(serviceAccountExp, buf.String(), false)
t.Fatalf("expected vs actual differs. Red text is missing and green text is extra.\n%v", dmp.DiffPrettyText(diffs))
Copy link
Member

Choose a reason for hiding this comment

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

This library did not work for me. I did not see a diff with different colors. it would be easier if we just printed out the mismatched lines IMO. Is there some section of a user guide that I have not updated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem a bit iffy. I think my macbook wasn't showing different colors, but it seems to be working right now on my thinkpad and in travis. It might have something to do with the way that the terminals handle escapes and color. This is the the way it's handled in diffmergepatch: https://github.com/sergi/go-diff/blob/master/diffmatchpatch/diff.go#L1183

If we want to keep using this library, we can either keep it like this or change to DiffToDelta, which would have an output like this instead (the numbers after =, -, and + are characters to keep, remove, or add respectively):

--- FAIL: TestGopkgtoml (0.00s)
        gopkgtoml_test.go:33: expected vs actual differs.
                =1548   -3      =72     +    unused-packages = false%0A

Copy link
Contributor

Choose a reason for hiding this comment

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

@AlexNPavel Is there any way to print out only the lines that differ for expected vs actual?
The above output is a little hard to comprehend.
The colorized diff works for me but like you pointed out its dependent on the terminal settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't look like the diffmergepatch library has any tools for printing lines that differ or outputting a more diff-like output. So we're kinda stuck with the above two options unless we move to a new library or make our own helper functions, which may not be that simple.

Copy link
Member

Choose a reason for hiding this comment

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

If it helps, I've been playing with this same library to get diffs out of the helm operator. Here's where I've ended up so far:

func diff(a, b string) string {
	dmp := diffmatchpatch.New()

	wSrc, wDst, warray := dmp.DiffLinesToRunes(a, b)
	diffs := dmp.DiffMainRunes(wSrc, wDst, false)
	diffs = dmp.DiffCharsToLines(diffs, warray)
	var buff bytes.Buffer
	for _, diff := range diffs {
		text := diff.Text

		switch diff.Type {
		case diffmatchpatch.DiffInsert:
			_, _ = buff.WriteString(prefixLines(text, "+"))
		case diffmatchpatch.DiffDelete:
			_, _ = buff.WriteString(prefixLines(text, "-"))
		case diffmatchpatch.DiffEqual:
			_, _ = buff.WriteString(prefixLines(text, " "))
		}
	}
	return buff.String()
}

func prefixLines(s, prefix string) string {
	var buf bytes.Buffer
	lines := strings.Split(s, "\n")
	ls := regexp.MustCompile("^")
	for _, line := range lines[:len(lines)-1] {
		buf.WriteString(ls.ReplaceAllString(line, prefix))
		buf.WriteString("\n")
	}
	return buf.String()
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joelanford that works very well. Thanks. Since this diff work is unrelated to this PR, I'll leave this PR as is and make a new PR to change that replaces the diffs in the current tests with your methods, plus color as that can improve readability in terminals that support it. The lines based method is much easier to read, especially if you're only modifying a couple characters in a line, which can become really messy with the DiffPrettyText method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah let's add in Joe's diff changes in a new PR.

*/
sa, err := ioutil.ReadFile("deploy/service_account.yaml")
if err != nil {
log.Fatalf("could not find sa manifest: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

could not find the manifest deploy/service_account.yaml

Copy link
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM after nit

@AlexNPavel AlexNPavel merged commit 934a03d into operator-framework:master Oct 17, 2018
@AlexNPavel AlexNPavel deleted the service-account-2 branch October 17, 2018 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants