Skip to content

Commit

Permalink
Merge pull request #13 from fabriziosestito/refactor/remove-easyjson
Browse files Browse the repository at this point in the history
refactor: remove easyjson
  • Loading branch information
flavio authored Aug 8, 2023
2 parents ee3f42e + 0756097 commit 8d334c0
Show file tree
Hide file tree
Showing 359 changed files with 322 additions and 80,385 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
on:
push:
branches:
- main
- main
tags:
- 'v*'
- "v*"

name: Release policy

jobs:

test:
name: run tests and linters
uses: kubewarden/github-actions/.github/workflows/[email protected].4
uses: kubewarden/github-actions/.github/workflows/[email protected].7

release:
needs: test
Expand All @@ -23,6 +22,6 @@ jobs:
# Required by cosign keyless signing
id-token: write

uses: kubewarden/github-actions/.github/workflows/[email protected].4
uses: kubewarden/github-actions/.github/workflows/[email protected].7
with:
oci-target: ghcr.io/${{ github.repository_owner }}/policies/namespace-label-propagator
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: Continuous integration
jobs:
test:
name: run tests and linters
uses: kubewarden/github-actions/.github/workflows/[email protected].4
uses: kubewarden/github-actions/.github/workflows/[email protected].7
14 changes: 3 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ SOURCE_FILES := $(shell find . -type f -name '*.go')
VERSION ?= $(shell git describe | cut -c2-)


policy.wasm: $(SOURCE_FILES) go.mod go.sum types_easyjson.go
policy.wasm: $(SOURCE_FILES) go.mod go.sum
docker run \
--rm \
-e GOFLAGS="-buildvcs=false" \
-v ${PWD}:/src \
-w /src tinygo/tinygo:0.27.0 \
-w /src tinygo/tinygo:0.28.1 \
tinygo build -o policy.wasm -target=wasi -no-debug .

artifacthub-pkg.yml: metadata.yml go.mod
Expand All @@ -25,16 +25,8 @@ artifacthub-pkg.yml: metadata.yml go.mod
annotated-policy.wasm: policy.wasm metadata.yml artifacthub-pkg.yml
kwctl annotate -m metadata.yml -u README.md -o annotated-policy.wasm policy.wasm

.PHONY: generate-easyjson
types_easyjson.go: types.go
docker run \
--rm \
-v ${PWD}:/src \
-w /src \
golang:1.20-alpine ./hack/generate-easyjson.sh

.PHONY: test
test: types_easyjson.go
test:
go test -v

.PHONY: e2e-tests
Expand Down
10 changes: 5 additions & 5 deletions artifacthub-pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@
#
# This config can be saved to its default location with:
# kwctl scaffold artifacthub > artifacthub-pkg.yml
version: 0.1.3
version: 0.1.4
name: namespace-label-propagator-policy
displayName: Namespace label propagator
createdAt: 2023-07-07T19:03:20.583059681Z
createdAt: 2023-08-03T15:51:35.18051825Z
description: Kubewarden policy designed to automatically propagate labels defined in a Kubernetes namespace to the associated resources within that namespace
license: Apache-2.0
homeURL: https://github.com/kubewarden/namespace-label-propagator-policy
containersImages:
- name: policy
image: ghcr.io/kubewarden/policies/namespace-label-propagator:v0.1.3
image: ghcr.io/kubewarden/policies/namespace-label-propagator:v0.1.4
keywords:
- policy
- kubewarden
- namespace
- label
links:
- name: policy
url: https://github.com/kubewarden/namespace-label-propagator-policy/releases/download/v0.1.3/policy.wasm
url: https://github.com/kubewarden/namespace-label-propagator-policy/releases/download/v0.1.4/policy.wasm
- name: source
url: https://github.com/kubewarden/namespace-label-propagator-policy
install: |
The policy can be obtained using [`kwctl`](https://github.com/kubewarden/kwctl):
```console
kwctl pull ghcr.io/kubewarden/policies/namespace-label-propagator:v0.1.3
kwctl pull ghcr.io/kubewarden/policies/namespace-label-propagator:v0.1.4
```
maintainers:
- name: Kubewarden developers
Expand Down
2 changes: 1 addition & 1 deletion e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# check if patch operation
patch=$(echo "${output}" | grep '{.*\"patch\".*}'| jq -r ".patch" | base64 --decode)
echo "patch=$patch"
echo ${patch} | jq -e "[.[].op == \"add\" and .[].value.cccenter == \"zpto\"] | any"
echo ${patch} | jq -e "[.[].op == \"add\" and .[].value.cccenter? == \"zpto\"] | any"
}

@test "Mutate resource with wrong labels value" {
Expand Down
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ module github.com/kubewarden/go-policy-template

go 1.20

replace github.com/go-openapi/strfmt => github.com/kubewarden/strfmt v0.1.2

require (
github.com/francoispqt/onelog v0.0.0-20190306043706-8c2bb31b10a4
github.com/kubewarden/k8s-objects v1.26.0-kw2
github.com/kubewarden/policy-sdk-go v0.4.1
github.com/mailru/easyjson v0.7.7
github.com/kubewarden/k8s-objects v1.27.0-kw2
github.com/kubewarden/policy-sdk-go v0.5.0
github.com/wapc/wapc-guest-tinygo v0.3.3
)

require (
github.com/francoispqt/gojay v0.0.0-20181220093123-f2cc13a668ca // indirect
github.com/go-openapi/strfmt v0.21.3 // indirect
github.com/josharian/intern v1.0.0 // indirect
)

replace github.com/go-openapi/strfmt => github.com/kubewarden/strfmt v0.1.3
19 changes: 8 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ github.com/francoispqt/gojay v0.0.0-20181220093123-f2cc13a668ca/go.mod h1:H8Wgri
github.com/francoispqt/onelog v0.0.0-20190306043706-8c2bb31b10a4 h1:N9eG+1y9e3tnNPXKjssLMa8MumIBDWWoJQWM7htGWUc=
github.com/francoispqt/onelog v0.0.0-20190306043706-8c2bb31b10a4/go.mod h1:v1Il1fkBpjiYPpEJcGxqgrPUPcHuTC7eHh9zBV3CLBE=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kubewarden/k8s-objects v1.26.0-kw2 h1:m0zIlifROK3vAy5zR90qRXdCPWQGJUuqagxHA5Bf+Bo=
github.com/kubewarden/k8s-objects v1.26.0-kw2/go.mod h1:IuIHLG1JtxjC1JnY7SyEEA9MukCh/FACcwpzaBjgdLQ=
github.com/kubewarden/policy-sdk-go v0.4.1 h1:MTGxJaWWH6dZBwCdZ+FYVUclxveGzW3p4kuUJiZw+7M=
github.com/kubewarden/policy-sdk-go v0.4.1/go.mod h1:pY1FrcuGdhnzzN31wNieAimI4+7rYWbtkP+tYGna0Ug=
github.com/kubewarden/strfmt v0.1.2 h1:S0YUVkPeyUMikz8QssbMzfd1MC5K8ZqxLI2zfF8euMs=
github.com/kubewarden/strfmt v0.1.2/go.mod h1:sqLlis8qlm4A4pnZsRyRjNxyH86fiM+7Ee7bO+uJk94=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/kubewarden/k8s-objects v1.27.0-kw2 h1:6ZA72SFtDSbCupwxlIyJimUzN0nSweMCUx5jUEnoxkw=
github.com/kubewarden/k8s-objects v1.27.0-kw2/go.mod h1:wVx4Rg1HKml8yewPwAHUWp1wYSAtBlKV/tsmteDuK1g=
github.com/kubewarden/policy-sdk-go v0.5.0 h1:JnSRf5pHjFzTNNp6jJbSP5a4cwzFzkUBjLujqJd+Z+w=
github.com/kubewarden/policy-sdk-go v0.5.0/go.mod h1:1IZXauwI5iCuOZj7tU58nE/SZFb/HsCmj3ZpDVStVQs=
github.com/kubewarden/strfmt v0.1.3 h1:bb+2rbotioROjCkziSt+hqnHXzOlumN94NxDKdV2kPI=
github.com/kubewarden/strfmt v0.1.3/go.mod h1:DXoaaIYwqW1LyyRoMeyxfHUU+VUSTNFdj38juCXfRzs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/wapc/wapc-guest-tinygo v0.3.3 h1:jLebiwjVSHLGnS+BRabQ6+XOV7oihVWAc05Hf1SbeR0=
github.com/wapc/wapc-guest-tinygo v0.3.3/go.mod h1:mzM3CnsdSYktfPkaBdZ8v88ZlfUDEy5Jh5XBOV3fYcw=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
33 changes: 0 additions & 33 deletions hack/generate-easyjson.sh

This file was deleted.

16 changes: 10 additions & 6 deletions settings.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package main

import (
kubewarden "github.com/kubewarden/policy-sdk-go"
kubewarden_protocol "github.com/kubewarden/policy-sdk-go/protocol"
"github.com/mailru/easyjson"

"encoding/json"
"errors"
"fmt"

kubewarden "github.com/kubewarden/policy-sdk-go"
kubewarden_protocol "github.com/kubewarden/policy-sdk-go/protocol"
)

type Settings struct {
PropagatedLabels []string `json:"propagatedLabels"`
}

// The Settings class is defined inside of the `types.go` file

// No special checks have to be done
Expand All @@ -26,15 +30,15 @@ func (s *Settings) Valid() (bool, error) {

func NewSettingsFromValidationReq(validationReq *kubewarden_protocol.ValidationRequest) (Settings, error) {
settings := Settings{}
err := easyjson.Unmarshal(validationReq.Settings, &settings)
err := json.Unmarshal(validationReq.Settings, &settings)
return settings, err
}

func validateSettings(payload []byte) ([]byte, error) {
logger.Info("validating settings")

settings := Settings{}
err := easyjson.Unmarshal(payload, &settings)
err := json.Unmarshal(payload, &settings)
if err != nil {
return kubewarden.RejectSettings(kubewarden.Message(fmt.Sprintf("Provided settings are not valid: %v", err)))
}
Expand Down
8 changes: 4 additions & 4 deletions settings_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"github.com/mailru/easyjson"
"encoding/json"
"testing"
)

func TestParsingSettingsWithNoValueProvided(t *testing.T) {
rawSettings := []byte(`{}`)
settings := &Settings{}
if err := easyjson.Unmarshal(rawSettings, settings); err != nil {
if err := json.Unmarshal(rawSettings, settings); err != nil {
t.Errorf("Unexpected error %+v", err)
}

Expand All @@ -25,7 +25,7 @@ func TestParsingSettingsWithNoValueProvided(t *testing.T) {
func TestParsingSettingsWithEmptyStringLabel(t *testing.T) {
rawSettings := []byte(`{"propagatedLabels": ["label", ""]}`)
settings := &Settings{}
if err := easyjson.Unmarshal(rawSettings, settings); err != nil {
if err := json.Unmarshal(rawSettings, settings); err != nil {
t.Errorf("Unexpected error %+v", err)
}

Expand All @@ -42,7 +42,7 @@ func TestParsingSettingsWithEmptyStringLabel(t *testing.T) {
func TestParsingSettingsWithNoLabels(t *testing.T) {
rawSettings := []byte(`{"propagatedLabels": []}`)
settings := &Settings{}
if err := easyjson.Unmarshal(rawSettings, settings); err != nil {
if err := json.Unmarshal(rawSettings, settings); err != nil {
t.Errorf("Unexpected error %+v", err)
}

Expand Down
23 changes: 0 additions & 23 deletions types.go

This file was deleted.

Loading

0 comments on commit 8d334c0

Please sign in to comment.