Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"io/ioutil"
"os"
"runtime"
"strings"
"github.com/ghodss/yaml"
CONSTRAINTS=`kubectl get crd -o json | jq -r '.items[] | select(.spec.group == "constraints.gatekeeper.sh") | .spec.names.kind'`
for c in $CONSTRAINTS
do
kubectl get $c -o json | jq -r '.items[] | select(.status.violations) | .status.violations'
done
package policy
import data.lib.core
# @title PrometheusRules must specify a prometheus label
#
# All PrometheusRules created on the cluster must contain a `prometheus` label
# with a value of `prometheus`. This ensures that the rule is found by the prometheus operator.
#
# @kinds monitoring.coreos.com/PrometheusRule
// PrintFirstCharacter prints the first character found in a file
func PrintFirstCharacter(path string) error {
contents, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("read file: %w", err)
}
firstCharacter := contents[0]
fmt.Println(firstCharacter)
// PrintFirstCharacter prints the first character found in a file
func PrintFirstCharacter(path string) error {
contents, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("read file: %w", err)
}
result := getFirstCharacter(contents)
fmt.Println(result)
@jpreese
jpreese / gatekeeper-panic-loop.txt
Created July 1, 2020 14:49
Gatekeeper beta-9 panic
{"level":"info","ts":1593614297.4539874,"logger":"setup","msg":"setting up cert rotation"}
{"level":"info","ts":1593614297.4541724,"logger":"setup","msg":"starting manager"}
{"level":"info","ts":1593614297.454658,"logger":"cert-rotation","msg":"starting cert rotator controller"}
{"level":"info","ts":1593614297.4549243,"logger":"controller-runtime.controller","msg":"Starting EventSource","controller":"validating-webhook-controller","source":"kind source: /, Kind="}
{"level":"info","ts":1593614297.45812,"logger":"readiness-tracker","msg":"config resource not found - skipping for readiness"}
{"level":"info","ts":1593614297.458221,"logger":"readiness-tracker","msg":"ExpectationsDone","gvk":"config.gatekeeper.sh/v1alpha1, Kind=Config","expectationCount":0}
{"level":"info","ts":1593614297.4635198,"logger":"readiness-tracker","msg":"ExpectationsDone","gvk":"templates.gatekeeper.sh/v1beta1, Kind=ConstraintTemplate","expectationCount":0}
{"level":"info","ts":1593614297.5550866,"logger":"cert-rotation","msg":"refreshin
@jpreese
jpreese / container_constraints.rego
Created June 23, 2020 15:46
Container constraints policy
package policy
import data.lib.k8s
violation[msg] {
containers_resource_constraints_required
msg := k8s.format(sprintf("(%s) %s: Container resource constraints must be specified", [k8s.kind, k8s.name]))
}
@jpreese
jpreese / kubernetes.rego
Last active June 23, 2020 15:49
Kubernetes rego library
package lib.k8s
default is_gatekeeper = false
is_gatekeeper {
has_field(input, "review")
has_field(input.review, "object")
}
object = input {
@jpreese
jpreese / unzip-test.yaml
Created June 9, 2020 01:01
unzip-container-test
schemaVersion: 2.0.0
commandTests:
- name: unzip
command: unzip
args: ["-v"]
@jpreese
jpreese / container-test.yaml
Created June 8, 2020 23:42
atlantis-structure-test
schemaVersion: 2.0.0
# Validate the environment contains the required tooling
commandTests:
- name: Atlantis
command: atlantis
args: ["version"]
- name: Terraform
command: terraform