-
Notifications
You must be signed in to change notification settings - Fork 1.8k
*: 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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,5 +84,4 @@ required = [ | |
[[prune.project]] | ||
name = "k8s.io/code-generator" | ||
non-go = false | ||
unused-packages = false | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,5 +88,4 @@ required = [ | |
[[prune.project]] | ||
name = "k8s.io/code-generator" | ||
non-go = false | ||
unused-packages = false | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2018 The Operator-SDK Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package scaffold | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
type ServiceAccount struct { | ||
input.Input | ||
} | ||
|
||
func (s *ServiceAccount) GetInput() (input.Input, error) { | ||
if s.Path == "" { | ||
s.Path = filepath.Join(deployDir, serviceAccountYamlFile) | ||
} | ||
s.TemplateBody = serviceAccountTemplate | ||
return s.Input, nil | ||
} | ||
|
||
const serviceAccountTemplate = `apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: {{.ProjectName}} | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2018 The Operator-SDK Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package scaffold | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/sergi/go-diff/diffmatchpatch" | ||
) | ||
|
||
func TestServiceAccount(t *testing.T) { | ||
s, buf := setupScaffoldAndWriter() | ||
err := s.Execute(appConfig, &ServiceAccount{}) | ||
if err != nil { | ||
t.Fatalf("failed to execute the scaffold: (%v)", err) | ||
} | ||
|
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()
} There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
const serviceAccountExp = `apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: app-operator | ||
` |
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.
+1 thank you for updating this file