1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

chore: organize constants better (#7941)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-07-31 13:53:57 +02:00 committed by GitHub
parent c38a014468
commit b6251c9894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 24 additions and 24 deletions

View file

@ -1,13 +1,13 @@
package kyverno
const (
// PodControllersAnnotation defines the annotation key for Pod-Controllers
PodControllersAnnotation = "pod-policies.kyverno.io/autogen-controllers"
// LabelAppManagedBy defines the label key for managed-by label
LabelAppManagedBy = "app.kubernetes.io/managed-by"
AnnotationPolicyCategory = "policies.kyverno.io/category"
AnnotationPolicySeverity = "policies.kyverno.io/severity"
AnnotationPolicyScored = "policies.kyverno.io/scored"
// ValueKyvernoApp defines the kyverno application value
// Well known labels
LabelAppManagedBy = "app.kubernetes.io/managed-by"
// Well known annotations
AnnotationAutogenControllers = "pod-policies.kyverno.io/autogen-controllers"
AnnotationPolicyCategory = "policies.kyverno.io/category"
AnnotationPolicySeverity = "policies.kyverno.io/severity"
AnnotationPolicyScored = "policies.kyverno.io/scored"
// Well known values
ValueKyvernoApp = "kyverno"
)

View file

@ -45,7 +45,7 @@ func Test_ClusterPolicy_Autogen_All(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "policy",
Annotations: map[string]string{
kyverno.PodControllersAnnotation: "all",
kyverno.AnnotationAutogenControllers: "all",
},
},
}

View file

@ -44,7 +44,7 @@ type ClusterPolicy struct {
// HasAutoGenAnnotation checks if a policy has auto-gen annotation
func (p *ClusterPolicy) HasAutoGenAnnotation() bool {
annotations := p.GetAnnotations()
val, ok := annotations[kyverno.PodControllersAnnotation]
val, ok := annotations[kyverno.AnnotationAutogenControllers]
if ok && strings.ToLower(val) != "none" {
return true
}

View file

@ -45,7 +45,7 @@ func Test_Policy_Autogen_All(t *testing.T) {
Name: "policy",
Namespace: "abcd",
Annotations: map[string]string{
kyverno.PodControllersAnnotation: "all",
kyverno.AnnotationAutogenControllers: "all",
},
},
}

View file

@ -45,7 +45,7 @@ type Policy struct {
// HasAutoGenAnnotation checks if a policy has auto-gen annotation
func (p *Policy) HasAutoGenAnnotation() bool {
annotations := p.GetAnnotations()
val, ok := annotations[kyverno.PodControllersAnnotation]
val, ok := annotations[kyverno.AnnotationAutogenControllers]
if ok && strings.ToLower(val) != "none" {
return true
}

View file

@ -29,7 +29,7 @@ func ToJSON(in apiextensions.JSON) *apiextv1.JSON {
// ValidatePolicyName validates policy name
func ValidateAutogenAnnotation(path *field.Path, annotations map[string]string) (errs field.ErrorList) {
value, ok := annotations[kyverno.PodControllersAnnotation]
value, ok := annotations[kyverno.AnnotationAutogenControllers]
if ok {
if value == "all" {
errs = append(errs, field.Forbidden(path, "Autogen annotation does not support 'all' anymore, remove the annotation or set it to a valid value"))

View file

@ -45,7 +45,7 @@ func Test_ClusterPolicy_Autogen_All(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "policy",
Annotations: map[string]string{
kyverno.PodControllersAnnotation: "all",
kyverno.AnnotationAutogenControllers: "all",
},
},
}

View file

@ -44,7 +44,7 @@ type ClusterPolicy struct {
// HasAutoGenAnnotation checks if a policy has auto-gen annotation
func (p *ClusterPolicy) HasAutoGenAnnotation() bool {
annotations := p.GetAnnotations()
val, ok := annotations[kyverno.PodControllersAnnotation]
val, ok := annotations[kyverno.AnnotationAutogenControllers]
if ok && strings.ToLower(val) != "none" {
return true
}

View file

@ -45,7 +45,7 @@ func Test_Policy_Autogen_All(t *testing.T) {
Name: "policy",
Namespace: "abcd",
Annotations: map[string]string{
kyverno.PodControllersAnnotation: "all",
kyverno.AnnotationAutogenControllers: "all",
},
},
}

View file

@ -44,7 +44,7 @@ type Policy struct {
// HasAutoGenAnnotation checks if a policy has auto-gen annotation
func (p *Policy) HasAutoGenAnnotation() bool {
annotations := p.GetAnnotations()
val, ok := annotations[kyverno.PodControllersAnnotation]
val, ok := annotations[kyverno.AnnotationAutogenControllers]
if ok && strings.ToLower(val) != "none" {
return true
}

View file

@ -127,7 +127,7 @@ func GetRequestedControllers(meta *metav1.ObjectMeta) []string {
if annotations == nil {
return nil
}
controllers, ok := annotations[kyverno.PodControllersAnnotation]
controllers, ok := annotations[kyverno.AnnotationAutogenControllers]
if !ok || controllers == "" {
return nil
}
@ -251,7 +251,7 @@ func computeRules(p kyvernov1.PolicyInterface) []kyvernov1.Rule {
desiredControllers = "none"
}
ann := p.GetAnnotations()
actualControllers, ok := ann[kyverno.PodControllersAnnotation]
actualControllers, ok := ann[kyverno.AnnotationAutogenControllers]
if !ok || !applyAutoGen {
actualControllers = desiredControllers
} else {

View file

@ -281,22 +281,22 @@ func Test_GetRequestedControllers(t *testing.T) {
},
{
name: "annotation-empty",
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.PodControllersAnnotation: ""}},
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.AnnotationAutogenControllers: ""}},
expectedControllers: nil,
},
{
name: "annotation-none",
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.PodControllersAnnotation: "none"}},
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.AnnotationAutogenControllers: "none"}},
expectedControllers: []string{},
},
{
name: "annotation-job",
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.PodControllersAnnotation: "Job"}},
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.AnnotationAutogenControllers: "Job"}},
expectedControllers: []string{"Job"},
},
{
name: "annotation-job-deployment",
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.PodControllersAnnotation: "Job,Deployment"}},
meta: metav1.ObjectMeta{Annotations: map[string]string{kyverno.AnnotationAutogenControllers: "Job,Deployment"}},
expectedControllers: []string{"Job", "Deployment"},
},
}

View file

@ -1133,7 +1133,7 @@ func jsonPatchOnPod(rule kyvernov1.Rule) bool {
func podControllerAutoGenExclusion(policy kyvernov1.PolicyInterface) bool {
annotations := policy.GetAnnotations()
val, ok := annotations[kyverno.PodControllersAnnotation]
val, ok := annotations[kyverno.AnnotationAutogenControllers]
if !ok || val == "none" {
return false
}