-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
204 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package example | ||
|
||
import ( | ||
"github.com/jasonrichardsmith/sentry/sentry" | ||
) | ||
|
||
type Config struct { | ||
sentry.Config `yaml:"-,inline"` | ||
} | ||
|
||
func (c *Config) LoadSentry() (sentry.Sentry, error) { | ||
return ExampleSentry{}, nil | ||
} |
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,42 @@ | ||
package example | ||
|
||
import "k8s.io/api/admission/v1beta1" | ||
|
||
var ( | ||
// Uncomment to deserialize | ||
/* | ||
scheme = runtime.NewScheme() | ||
codecs = serializer.NewCodecFactory(scheme) | ||
*/ | ||
) | ||
|
||
// ExampleSentry satisfies sentry.Sentry interface | ||
type ExampleSentry struct{} | ||
|
||
// Type returns the type of object you are checking | ||
func (es ExampleSentry) Type() string { | ||
// Return your type here. | ||
return "Pod" | ||
} | ||
|
||
// This is your validating function | ||
func (es ExampleSentry) Admit(receivedAdmissionReview v1beta1.AdmissionReview) *v1beta1.AdmissionResponse { | ||
|
||
reviewResponse := v1beta1.AdmissionResponse{} | ||
// This is an en example of how to deserialize an object. | ||
/* | ||
raw := receivedAdmissionReview.Request.Object.Raw | ||
pod := corev1.Pod{} | ||
deserializer := codecs.UniversalDeserializer() | ||
reviewResponse := v1beta1.AdmissionResponse{} | ||
if _, _, err := deserializer.Decode(raw, nil, &pod); err != nil { | ||
log.Error(err) | ||
reviewResponse.Result = &metav1.Status{Message: err.Error()} | ||
return &reviewResponse | ||
} | ||
*/ | ||
// Here you would validate your pod | ||
// We are just returning true here. | ||
reviewResponse.Allowed = true | ||
return &reviewResponse | ||
} |
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,30 @@ | ||
package example | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/api/admission/v1beta1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestType(t *testing.T) { | ||
ts := ExampleSentry{} | ||
if ts.Type() != "Pod" { | ||
t.Fatal("Failed type test") | ||
} | ||
} | ||
|
||
func TestAdmit(t *testing.T) { | ||
s := ExampleSentry{} | ||
ar := v1beta1.AdmissionReview{ | ||
Request: &v1beta1.AdmissionRequest{ | ||
Object: runtime.RawExtension{ | ||
Raw: make([]byte, 0), | ||
}, | ||
}, | ||
} | ||
resp := s.Admit(ar) | ||
if !resp.Allowed { | ||
t.Fatal("expected passing review") | ||
} | ||
} |
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
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,17 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: test3 | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: pass | ||
namespace: test3 | ||
labels: | ||
test: label | ||
spec: | ||
containers: | ||
- name: pause | ||
image: gcr.io/google_containers/pause-amd64:3.0 |