-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reuse code moved in kyverno repo (#498)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
- Loading branch information
1 parent
c323703
commit da1586c
Showing
16 changed files
with
89 additions
and
492 deletions.
There are no files selected for viewing
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,39 @@ | ||
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/resource" | ||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource/convert" | ||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource/loader" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var ( | ||
exceptionV1 = schema.GroupVersion(kyvernov2alpha1.GroupVersion).WithKind("PolicyException") | ||
exceptionV2 = schema.GroupVersion(kyvernov2beta1.GroupVersion).WithKind("PolicyException") | ||
) | ||
|
||
func Load(l loader.Loader, content []byte) ([]*kyvernov2alpha1.PolicyException, error) { | ||
untyped, err := resource.LoadResources(l, content) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var exceptions []*kyvernov2alpha1.PolicyException | ||
for _, object := range untyped { | ||
gvk := object.GroupVersionKind() | ||
switch gvk { | ||
case exceptionV1, exceptionV2: | ||
exception, err := convert.To[kyvernov2alpha1.PolicyException](object) | ||
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.