-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Frank Jogeleit <[email protected]>
- Loading branch information
Frank Jogeleit
committed
Oct 19, 2023
1 parent
5d51460
commit 48d0e73
Showing
9 changed files
with
388 additions
and
341 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,45 @@ | ||
package exception | ||
|
||
import ( | ||
"fmt" | ||
|
||
kyvernov2alpha1 "github.com/kyverno/kyverno/api/kyverno/v2alpha1" | ||
kyvernov2beta1 "github.com/kyverno/kyverno/api/kyverno/v2beta1" | ||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/data" | ||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource/convert" | ||
resourceloader "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource/loader" | ||
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/kubectl-validate/pkg/openapiclient" | ||
) | ||
|
||
var ( | ||
factory, _ = resourceloader.New(openapiclient.NewComposite(openapiclient.NewLocalCRDFiles(data.Crds(), data.CrdsFolder))) | ||
exceptionV1 = schema.GroupVersion(kyvernov2alpha1.GroupVersion).WithKind("PolicyException") | ||
exceptionV2 = schema.GroupVersion(kyvernov2beta1.GroupVersion).WithKind("PolicyException") | ||
) | ||
|
||
func Load(content []byte) ([]*kyvernov2beta1.PolicyException, error) { | ||
documents, err := yamlutils.SplitDocuments(content) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var exceptions []*kyvernov2beta1.PolicyException | ||
for _, document := range documents { | ||
gvk, untyped, err := factory.Load(document) | ||
if err != nil { | ||
return nil, err | ||
} | ||
switch gvk { | ||
case exceptionV1, exceptionV2: | ||
exception, err := convert.To[kyvernov2beta1.PolicyException](untyped) | ||
if err != nil { | ||
return nil, err | ||
} | ||
exceptions = append(exceptions, exception) | ||
default: | ||
return nil, fmt.Errorf("policy exception type not supported %s", gvk) | ||
} | ||
} | ||
return exceptions, 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
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