-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from reactiveops/jg/container-fun
jg/container fun
- Loading branch information
Showing
4 changed files
with
100 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
deploy | ||
.gitignore | ||
Dockerfile | ||
LICENSE | ||
Tiltfile |
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,78 @@ | ||
// Copyright 2018 ReactiveOps | ||
// | ||
// 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 validator | ||
|
||
import ( | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
type containerResults struct { | ||
Name string | ||
Reason string | ||
} | ||
|
||
func validateContainer(container corev1.Container) containerResults { | ||
var sb strings.Builder | ||
c := containerResults{ | ||
Name: container.Name, | ||
} | ||
|
||
resources(container, sb) | ||
probes(container, sb) | ||
tag(container, sb) | ||
|
||
c.Reason = sb.String() | ||
return c | ||
} | ||
|
||
func resources(c corev1.Container, sb strings.Builder) string { | ||
log.Info("validating Container:", "container resources", c.Resources) | ||
if c.Resources.Requests.Cpu().IsZero() { | ||
sb.WriteString("- CPU requests are not set.\n") | ||
} | ||
if c.Resources.Requests.Memory().IsZero() { | ||
sb.WriteString("- Memory requests are not set.\n") | ||
} | ||
if c.Resources.Limits.Cpu().IsZero() { | ||
sb.WriteString("- CPU limits are not set.\n") | ||
} | ||
if c.Resources.Limits.Memory().IsZero() { | ||
sb.WriteString("- Memory limits are not set.\n") | ||
} | ||
|
||
return sb.String() | ||
} | ||
|
||
func probes(c corev1.Container, sb strings.Builder) string { | ||
if c.ReadinessProbe == nil { | ||
sb.WriteString("- Readiness Probe is not set.\n") | ||
} | ||
|
||
if c.LivenessProbe == nil { | ||
sb.WriteString("- Liveness Probe is not set.\n") | ||
} | ||
return sb.String() | ||
} | ||
|
||
func tag(c corev1.Container, sb strings.Builder) string { | ||
img := strings.Split(c.Image, ":") | ||
if len(img) == 1 || img[1] == "latest" { | ||
sb.WriteString("- Image tag is latest.\n") | ||
} | ||
|
||
return sb.String() | ||
} |
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