-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- filter kubectl apply output and extract errors - limit apply output to 20K charts (avoid reaching max etcd size) - log kubectl exit code when the process is killed Signed-off-by: Stefan Prodan <[email protected]>
- Loading branch information
1 parent
4da53d1
commit a95ddaf
Showing
3 changed files
with
80 additions
and
37 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,68 @@ | ||
/* | ||
Copyright 2020 The Flux 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 controllers | ||
|
||
import "strings" | ||
|
||
// parseApplyOutput extracts the objects and the action | ||
// performed by kubectl (created, configured, unchanged) | ||
func parseApplyOutput(in []byte) map[string]string { | ||
result := make(map[string]string) | ||
input := strings.Split(string(in), "\n") | ||
if len(input) == 0 { | ||
return result | ||
} | ||
var parts []string | ||
for _, str := range input { | ||
if str != "" { | ||
parts = append(parts, str) | ||
} | ||
} | ||
for _, str := range parts { | ||
kv := strings.Split(str, " ") | ||
if len(kv) > 1 { | ||
result[kv[0]] = kv[1] | ||
} | ||
} | ||
return result | ||
} | ||
|
||
// parseApplyError extracts the errors from the kubectl | ||
// apply output by removing the successfully applied objects | ||
func parseApplyError(in []byte) string { | ||
errors := "" | ||
lines := strings.Split(string(in), "\n") | ||
for _, line := range lines { | ||
if line != "" && | ||
!strings.HasSuffix(line, "created") && | ||
!strings.HasSuffix(line, "configured") && | ||
!strings.HasSuffix(line, "unchanged") { | ||
errors += line + "\n" | ||
} | ||
} | ||
|
||
return errors | ||
} | ||
|
||
func containsString(slice []string, s string) bool { | ||
for _, item := range slice { | ||
if item == s { | ||
return true | ||
} | ||
} | ||
return false | ||
} |