Skip to content

Commit

Permalink
Merge pull request #714 from Vyom-Yadav/bumpKyvernoVersion
Browse files Browse the repository at this point in the history
feat: bump go version to 1.20 and bump dependency versions
  • Loading branch information
Vyom-Yadav authored May 24, 2023
2 parents 522ea83 + e8d236e commit 1746c3e
Show file tree
Hide file tree
Showing 12 changed files with 2,864 additions and 777 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: v1.18
go-version: v1.20

- name: Unit Test
run: ./tests/test-go-unit.sh
Expand All @@ -30,7 +30,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: v1.18
go-version: v1.20

- name: Setup Env
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.20
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
38 changes: 29 additions & 9 deletions src/admissioncontrollerpolicy/admissionControllerPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package admissioncontrollerpolicy
import (
"context"
"fmt"
"path/filepath"
"regexp"
"strings"

"github.com/accuknox/auto-policy-discovery/src/cluster"
cfg "github.com/accuknox/auto-policy-discovery/src/config"
"github.com/accuknox/auto-policy-discovery/src/libs"
Expand All @@ -15,12 +19,9 @@ import (
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"github.com/rs/zerolog"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"path/filepath"
"regexp"
"sigs.k8s.io/yaml"
"strings"
)

var log *zerolog.Logger
Expand Down Expand Up @@ -142,8 +143,13 @@ func ConvertPoliciesToWorkerResponse(policies []kyvernov1.Policy) *wpb.WorkerRes
}

// AutoGenPrecondition generates a preconditions matching on particular labels for kyverno policy
func AutoGenPrecondition(templateKey string, labels types.LabelMap, precondition apiextensions.JSON) apiextensions.JSON {
preconditionMap := precondition.(map[string]interface{})
func AutoGenPrecondition(templateKey string, labels types.LabelMap, precondition apiextv1.JSON) apiextv1.JSON {
var preconditionMap map[string]interface{}
err := json.Unmarshal(precondition.Raw, &preconditionMap)
if err != nil {
log.Error().Msgf("unmarshalling precondition failed err=%v", err.Error())
return precondition
}
for key, value := range labels {
newPrecondition := map[string]interface{}{
"key": "{{ request.object.spec." + templateKey + ".metadata.labels." + key + " || '' }}",
Expand All @@ -153,17 +159,31 @@ func AutoGenPrecondition(templateKey string, labels types.LabelMap, precondition
existingSlice := preconditionMap["all"].([]interface{})
preconditionMap["all"] = append(existingSlice, newPrecondition)
}
return preconditionMap
newPrecondition, err := json.Marshal(preconditionMap)
if err != nil {
log.Error().Msgf("marshalling precondition failed err=%v", err.Error())
return precondition
}
return apiextv1.JSON{
Raw: newPrecondition,
}
}

// AutoGenPattern generates a pattern changing validation pattern from Pod to high level controller
func AutoGenPattern(templateKey string, pattern apiextensions.JSON) apiextensions.JSON {
func AutoGenPattern(templateKey string, pattern apiextv1.JSON) apiextv1.JSON {
newPattern := map[string]interface{}{
"spec": map[string]interface{}{
templateKey: pattern,
},
}
return newPattern
newPatternBytes, err := json.Marshal(newPattern)
if err != nil {
log.Error().Msgf("marshalling pattern failed err=%v", err.Error())
return pattern
}
return apiextv1.JSON{
Raw: newPatternBytes,
}
}

// ShouldSATokenBeAutoMounted returns true if service account token should be auto mounted
Expand Down
2 changes: 1 addition & 1 deletion src/build/Dockerfile.autopol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Builder

FROM golang:1.18.0-bullseye as builder
FROM golang:1.20.0-bullseye as builder

WORKDIR /usr/src/knox

Expand Down
2 changes: 1 addition & 1 deletion src/feedconsumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (cfc *KnoxFeedConsumer) startConsumerPulsar() {

default:
ev := <-pulsarReceiver
sub.Ack(ev)
_ = sub.Ack(ev)
run = cfc.HandlePollEvent(ev.Message)
}
}
Expand Down
Loading

0 comments on commit 1746c3e

Please sign in to comment.