Skip to content

Commit

Permalink
Merge pull request #719 from fluxcd/ssa-skip-clusterrole-normalization
Browse files Browse the repository at this point in the history
ssa: Skip normalization of Roles and ClusterRoles
  • Loading branch information
stefanprodan authored Jan 18, 2024
2 parents 58b2a7e + 2cd5930 commit 6f62989
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ssa/normalize/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func UnstructuredList(objects []*unstructured.Unstructured) error {
// certain standard fields are removed.
func UnstructuredListWithScheme(objects []*unstructured.Unstructured, scheme *runtime.Scheme) error {
for _, o := range objects {
// Skip Role and ClusterRole objects to avoid resetting the rules due to upstream serialization bug.
// xref:https://github.com/fluxcd/kustomize-controller/issues/1041
if o.GetAPIVersion() == "rbac.authorization.k8s.io/v1" &&
(o.GetKind() == "Role" || o.GetKind() == "ClusterRole") {
continue
}

if err := UnstructuredWithScheme(o, scheme); err != nil {
return fmt.Errorf("%s normalization error: %w", utils.FmtUnstructured(o), err)
}
Expand Down
22 changes: 22 additions & 0 deletions ssa/normalize/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/google/go-cmp/cmp"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -35,6 +36,27 @@ func TestFromUnstructured(t *testing.T) {
want metav1.Object
wantErr bool
}{
{
name: "no rules ClusterRole",
object: &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRole",
"metadata": map[string]interface{}{
"name": "test-clusterrole",
},
},
},
want: &rbacv1.ClusterRole{
TypeMeta: metav1.TypeMeta{
APIVersion: "rbac.authorization.k8s.io/v1",
Kind: "ClusterRole",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-clusterrole",
},
},
},
{
name: "valid Pod",
object: &unstructured.Unstructured{
Expand Down

0 comments on commit 6f62989

Please sign in to comment.