-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding step 'pods converge to selector' + fix: CI & syntax (#147)
* feat: adding step 'pods converge to selector' * docs(syntax-generation): better handling of bracket replacements * docs(syntax-generation): using bracket replacements * chore: finish ToDo * chore: linter suggested changes * test: adding TestPodsInNamespaceWithLabelSelectorConvergeToFieldSelector * ci: adding codecov.yml * ci: codecov/codecov-action@v4 * ci: adding CODECOV_TOKEN * ci: attempt separation * ci: attempt separation 2 * ci: final separation * ci: updating codecov.yml * test: adding more UTs * chore: (?:converge to|have)
- Loading branch information
1 parent
4445cb6
commit 5b5a76b
Showing
14 changed files
with
667 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: CI | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
build: | ||
name: syntax | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: ^1.19 | ||
id: go | ||
- uses: actions/checkout@v4 | ||
- run: make check-syntax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
coverage: | ||
range: "70...90" | ||
round: down | ||
precision: 2 | ||
|
||
ignore: | ||
- "examples" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
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 replace | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
const regExp_CharsWithinBrackets = "([^(]*)" | ||
|
||
type Replacement struct { | ||
Replacee string | ||
Replacer string | ||
} | ||
|
||
func (r Replacement) Replace(src string) string { | ||
return strings.ReplaceAll(src, r.Replacee, r.Replacer) | ||
} | ||
|
||
type Replacements []Replacement | ||
|
||
func (rs Replacements) Replace(src string) string { | ||
new := src | ||
for _, r := range rs { | ||
new = r.Replace(new) | ||
} | ||
return new | ||
} | ||
|
||
type BracketsReplacement struct { | ||
Opening Replacement | ||
Closing Replacement | ||
} | ||
|
||
func (br BracketsReplacement) Replace(src string) string { | ||
re, err := regexp.Compile(br.getRegExp()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
new := re.ReplaceAllFunc([]byte(src), br.replaceSingle) | ||
return string(new) | ||
} | ||
|
||
func (br BracketsReplacement) replaceSingle(src []byte) []byte { | ||
s := string(src) | ||
s = br.Opening.Replace(s) | ||
s = br.Closing.Replace(s) | ||
return []byte(s) | ||
} | ||
|
||
func (br BracketsReplacement) getRegExp() string { | ||
return escapeEveryCharacter(br.Opening.Replacee) + | ||
regExp_CharsWithinBrackets + | ||
escapeEveryCharacter(br.Closing.Replacee) | ||
} | ||
|
||
func escapeEveryCharacter(s string) string { | ||
var buffer bytes.Buffer | ||
for _, c := range s { | ||
buffer.WriteString(`\`) | ||
buffer.WriteRune(c) | ||
} | ||
return buffer.String() | ||
} | ||
|
||
type BracketsReplacements []BracketsReplacement | ||
|
||
func (brs BracketsReplacements) Replace(src string) string { | ||
new := src | ||
for _, br := range brs { | ||
new = br.Replace(new) | ||
} | ||
return new | ||
} |
Oops, something went wrong.