Skip to content

Commit

Permalink
Fix unless no subresource tests, add go action caching
Browse files Browse the repository at this point in the history
Signed-off-by: Micah Hausler <[email protected]>
  • Loading branch information
micahhausler committed Nov 11, 2024
1 parent 551642e commit f305d11
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 25 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,23 @@ jobs:
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Restore cached modules
id: go-buildcache-restore
uses: actions/cache/restore@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
- name: Build
run: make build

- name: Save cached modules
id: go-buildcache-save
uses: actions/cache/save@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go-version }}-${{ hashFiles('**/go.sum') }}
- name: Run unit tests
run: make test
3 changes: 2 additions & 1 deletion internal/convert/testdata/cluster-admin.cedar
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ permit (
principal in k8s::Group::"system:masters",
action,
resource is k8s::Resource
);
)
unless { resource has subresource };
18 changes: 12 additions & 6 deletions internal/convert/testdata/crazy-policy.cedar
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ when
principal.name == "crazy-service-account" &&
["batch", "batch.k8s.aws"].contains(resource.apiGroup) &&
["jobs", "cronjobs"].contains(resource.resource)
};
}
unless { resource has subresource };

@clusterRoleBinding("crazy-policy")
@clusterRole("crazy-policy")
Expand All @@ -27,7 +28,8 @@ when
principal.namespace == "default" &&
principal.name == "crazy-service-account" &&
resource.resource == "something"
};
}
unless { resource has subresource };

@clusterRoleBinding("crazy-policy")
@clusterRole("crazy-policy")
Expand Down Expand Up @@ -109,7 +111,8 @@ when
(
resource.apiGroup
)
};
}
unless { resource has subresource };

@clusterRoleBinding("crazy-policy")
@clusterRole("crazy-policy")
Expand Down Expand Up @@ -145,7 +148,8 @@ when
resource.resource == "configmaps" &&
resource has name &&
resource.name == "aws-auth"
};
}
unless { resource has subresource };

@clusterRoleBinding("crazy-policy")
@clusterRole("crazy-policy")
Expand All @@ -163,7 +167,8 @@ when
resource.resource == "configmaps" &&
resource has name &&
["kubeadm-config", "kube-proxy", "coredns"].contains(resource.name)
};
}
unless { resource has subresource };

@clusterRoleBinding("crazy-policy")
@clusterRole("crazy-policy")
Expand All @@ -178,4 +183,5 @@ when
principal.namespace == "default" &&
principal.name == "crazy-service-account" &&
resource.apiGroup == ""
};
}
unless { resource has subresource };
3 changes: 2 additions & 1 deletion internal/convert/testdata/kubeadm:get-nodes.cedar
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ permit (
action == k8s::Action::"get",
resource is k8s::Resource
)
when { resource.apiGroup == "" && resource.resource == "nodes" };
when { resource.apiGroup == "" && resource.resource == "nodes" }
unless { resource has subresource };
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ when
principal.name == "horizontal-pod-autoscaler" &&
resource.apiGroup == "autoscaling" &&
resource.resource == "horizontalpodautoscalers"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:controller:horizontal-pod-autoscaler")
@clusterRole("system:controller:horizontal-pod-autoscaler")
Expand Down Expand Up @@ -81,7 +82,8 @@ when
principal.name == "horizontal-pod-autoscaler" &&
resource.apiGroup == "" &&
resource.resource == "pods"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:controller:horizontal-pod-autoscaler")
@clusterRole("system:controller:horizontal-pod-autoscaler")
Expand All @@ -97,7 +99,8 @@ when
principal.name == "horizontal-pod-autoscaler" &&
resource.apiGroup == "metrics.k8s.io" &&
resource.resource == "pods"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:controller:horizontal-pod-autoscaler")
@clusterRole("system:controller:horizontal-pod-autoscaler")
Expand All @@ -112,7 +115,8 @@ when
principal.namespace == "kube-system" &&
principal.name == "horizontal-pod-autoscaler" &&
resource.apiGroup == "custom.metrics.k8s.io"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:controller:horizontal-pod-autoscaler")
@clusterRole("system:controller:horizontal-pod-autoscaler")
Expand All @@ -127,7 +131,8 @@ when
principal.namespace == "kube-system" &&
principal.name == "horizontal-pod-autoscaler" &&
resource.apiGroup == "external.metrics.k8s.io"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:controller:horizontal-pod-autoscaler")
@clusterRole("system:controller:horizontal-pod-autoscaler")
Expand All @@ -144,4 +149,5 @@ when
principal.name == "horizontal-pod-autoscaler" &&
["", "events.k8s.io"].contains(resource.apiGroup) &&
resource.resource == "events"
};
}
unless { resource has subresource };
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ when
resource.resource == "secrets" &&
resource has namespace &&
resource.namespace == "kube-system"
};
}
unless { resource has subresource };

@roleBinding("system:controller:token-cleaner")
@role("system:controller:token-cleaner")
Expand All @@ -39,4 +40,5 @@ when
resource.resource == "events" &&
resource has namespace &&
resource.namespace == "kube-system"
};
}
unless { resource has subresource };
6 changes: 4 additions & 2 deletions internal/convert/testdata/system:coredns.cedar
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ when
principal.name == "coredns" &&
resource.apiGroup == "" &&
["endpoints", "services", "pods", "namespaces"].contains(resource.resource)
};
}
unless { resource has subresource };

@clusterRoleBinding("system:coredns")
@clusterRole("system:coredns")
Expand All @@ -28,4 +29,5 @@ when
principal.name == "coredns" &&
resource.apiGroup == "discovery.k8s.io" &&
resource.resource == "endpointslices"
};
}
unless { resource has subresource };
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ permit (
action in [k8s::Action::"list", k8s::Action::"watch"],
resource is k8s::Resource
)
when { principal.name == "system:kube-controller-manager" };
when { principal.name == "system:kube-controller-manager" }
unless { resource has subresource };

@clusterRoleBinding("system:kube-controller-manager")
@clusterRole("system:kube-controller-manager")
Expand Down
12 changes: 8 additions & 4 deletions internal/convert/testdata/system:node-proxier.cedar
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ when
principal.name == "system:kube-proxy" &&
resource.apiGroup == "" &&
["endpoints", "services"].contains(resource.resource)
};
}
unless { resource has subresource };

@clusterRoleBinding("system:node-proxier")
@clusterRole("system:node-proxier")
Expand All @@ -26,7 +27,8 @@ when
principal.name == "system:kube-proxy" &&
resource.apiGroup == "" &&
resource.resource == "nodes"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:node-proxier")
@clusterRole("system:node-proxier")
Expand All @@ -42,7 +44,8 @@ when
principal.name == "system:kube-proxy" &&
["", "events.k8s.io"].contains(resource.apiGroup) &&
resource.resource == "events"
};
}
unless { resource has subresource };

@clusterRoleBinding("system:node-proxier")
@clusterRole("system:node-proxier")
Expand All @@ -57,4 +60,5 @@ when
principal.name == "system:kube-proxy" &&
resource.apiGroup == "discovery.k8s.io" &&
resource.resource == "endpointslices"
};
}
unless { resource has subresource };

0 comments on commit f305d11

Please sign in to comment.