1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-05 15:37:19 +00:00

658 removing unused commented out code

This commit is contained in:
shravan 2020-02-07 15:02:36 +05:30
parent 88083e91d6
commit 70ea63cab3
3 changed files with 0 additions and 266 deletions

View file

@ -249,25 +249,6 @@ func Test_Validate_ResourceDescription_MatchedValid(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
} }
//func Test_Validate_ResourceDescription_MissingKindsOnMatched(t *testing.T) {
// var err error
// matchedResourcedescirption := []byte(`
// {
// "selector": {
// "matchLabels": {
// "app.type": "prod"
// }
// }
// }`)
//
// var rd kyverno.ResourceDescription
// err = json.Unmarshal(matchedResourcedescirption, &rd)
// assert.NilError(t, err)
//
// _, err = validateMatchedResourceDescription(rd)
// assert.Assert(t, err != nil)
//}
func Test_Validate_ResourceDescription_MissingKindsOnExclude(t *testing.T) { func Test_Validate_ResourceDescription_MissingKindsOnExclude(t *testing.T) {
var err error var err error
excludeResourcedescirption := []byte(` excludeResourcedescirption := []byte(`

View file

@ -31,196 +31,6 @@ func TestGetAnchorsFromMap_ThereAreAnchors(t *testing.T) {
assert.Equal(t, actualMap["(namespace)"].(string), "kube-?olicy") assert.Equal(t, actualMap["(namespace)"].(string), "kube-?olicy")
} }
//func TestValidate_ServiceTest(t *testing.T) {
// rawPolicy := []byte(`{
// "apiVersion":"kyverno.nirmata.io/v1",
// "kind":"ClusterPolicy",
// "metadata":{
// "name":"policy-service"
// },
// "spec":{
// "rules":[
// {
// "name":"ps1",
// "resource":{
// "kinds":[
// "Service"
// ],
// "name":"game-service*"
// },
// "mutate":{
// "patches":[
// {
// "path":"/metadata/labels/isMutated",
// "op":"add",
// "value":"true"
// },
// {
// "path":"/metadata/labels/secretLabel",
// "op":"replace",
// "value":"weKnow"
// },
// {
// "path":"/metadata/labels/originalLabel",
// "op":"remove"
// },
// {
// "path":"/spec/selector/app",
// "op":"replace",
// "value":"mutedApp"
// }
// ]
// },
// "validate":{
// "message":"This resource is broken",
// "pattern":{
// "spec":{
// "ports":[
// {
// "name":"hs",
// "protocol":32
// }
// ]
// }
// }
// }
// }
// ]
// }
// }`)
// rawResource := []byte(`{
// "kind":"Service",
// "apiVersion":"v1",
// "metadata":{
// "name":"game-service",
// "labels":{
// "originalLabel":"isHere",
// "secretLabel":"thisIsMySecret"
// }
// },
// "spec":{
// "selector":{
// "app":"MyApp"
// },
// "ports":[
// {
// "name":"http",
// "protocol":"TCP",
// "port":80,
// "targetPort":9376
// }
// ]
// }
// }
// `)
//
// var policy kyverno.ClusterPolicy
// json.Unmarshal(rawPolicy, &policy)
//
// resourceUnstructured, err := utils.ConvertToUnstructured(rawResource)
// assert.NilError(t, err)
//
// er := Validate(PolicyContext{Policy: policy, NewResource: *resourceUnstructured})
// assert.Assert(t, len(er.PolicyResponse.Rules) == 0)
//}
//
//func TestValidate_MapHasFloats(t *testing.T) {
// rawPolicy := []byte(`{
// "apiVersion":"kyverno.nirmata.io/v1",
// "kind":"ClusterPolicy",
// "metadata":{
// "name":"policy-deployment-changed"
// },
// "spec":{
// "rules":[
// {
// "name":"First policy v2",
// "resource":{
// "kinds":[
// "Deployment"
// ],
// "name":"nginx-*"
// },
// "mutate":{
// "patches":[
// {
// "path":"/metadata/labels/isMutated",
// "op":"add",
// "value":"true"
// },
// {
// "path":"/metadata/labels/app",
// "op":"replace",
// "value":"nginx_is_mutated"
// }
// ]
// },
// "validate":{
// "message":"replicas number is wrong",
// "pattern":{
// "metadata":{
// "labels":{
// "app":"*"
// }
// },
// "spec":{
// "replicas":3
// }
// }
// }
// }
// ]
// }
// }`)
// rawResource := []byte(`{
// "apiVersion":"apps/v1",
// "kind":"Deployment",
// "metadata":{
// "name":"nginx-deployment",
// "labels":{
// "app":"nginx"
// }
// },
// "spec":{
// "replicas":3,
// "selector":{
// "matchLabels":{
// "app":"nginx"
// }
// },
// "template":{
// "metadata":{
// "labels":{
// "app":"nginx"
// }
// },
// "spec":{
// "containers":[
// {
// "name":"nginx",
// "image":"nginx:1.7.9",
// "ports":[
// {
// "containerPort":80
// }
// ]
// }
// ]
// }
// }
// }
// }
// `)
//
// var policy kyverno.ClusterPolicy
// json.Unmarshal(rawPolicy, &policy)
//
// resourceUnstructured, err := utils.ConvertToUnstructured(rawResource)
// assert.NilError(t, err)
// er := Validate(PolicyContext{Policy: policy, NewResource: *resourceUnstructured})
// assert.Assert(t, len(er.PolicyResponse.Rules) == 0)
//}
func TestValidate_image_tag_fail(t *testing.T) { func TestValidate_image_tag_fail(t *testing.T) {
// If image tag is latest then imagepull policy needs to be checked // If image tag is latest then imagepull policy needs to be checked
rawPolicy := []byte(`{ rawPolicy := []byte(`{

View file

@ -82,21 +82,6 @@ func (ps *PolicyStore) Register(policy kyverno.ClusterPolicy) {
} }
} }
////LookUp look up the resources
//func (ps *PolicyStore) LookUp(kind, namespace string) ([]kyverno.ClusterPolicy, error) {
// ret := []kyverno.ClusterPolicy{}
// // lookup meta-store
// policyNames := ps.lookUp(kind, namespace)
// for _, policyName := range policyNames {
// policy, err := ps.pLister.Get(policyName)
// if err != nil {
// return nil, err
// }
// ret = append(ret, *policy)
// }
// return ret, nil
//}
func (ps *PolicyStore) ListAll() ([]kyverno.ClusterPolicy, error) { func (ps *PolicyStore) ListAll() ([]kyverno.ClusterPolicy, error) {
policyPointers, err := ps.pLister.List(labels.NewSelector()) policyPointers, err := ps.pLister.List(labels.NewSelector())
if err != nil { if err != nil {
@ -140,48 +125,6 @@ func (ps *PolicyStore) UnRegister(policy kyverno.ClusterPolicy) error {
return nil return nil
} }
////LookUp lookups up the policies for kind and namespace
//// returns a list of <policy, rule> that statisfy the filters
//func (ps *PolicyStore) lookUp(kind, namespace string) []string {
// ps.mu.RLock()
// defer ps.mu.RUnlock()
// var policyMap policyMap
// var ret []string
// // kind
// kindMap := ps.getKind(kind)
// if kindMap == nil {
// return []string{}
// }
// // get namespace specific policies
// policyMap = kindMap[namespace]
// ret = append(ret, transform(policyMap)...)
// // get policies on all namespaces
// policyMap = kindMap["*"]
// ret = append(ret, transform(policyMap)...)
// return unique(ret)
//}
//
//func unique(intSlice []string) []string {
// keys := make(map[string]bool)
// list := []string{}
// for _, entry := range intSlice {
// if _, value := keys[entry]; !value {
// keys[entry] = true
// list = append(list, entry)
// }
// }
// return list
//}
//
//// generates a copy
//func transform(pmap policyMap) []string {
// ret := []string{}
// for k := range pmap {
// ret = append(ret, k)
// }
// return ret
//}
func (ps *PolicyStore) addKind(kind string) namespaceMap { func (ps *PolicyStore) addKind(kind string) namespaceMap {
val, ok := ps.data[kind] val, ok := ps.data[kind]
if ok { if ok {