Skip to content

Commit f4edca3

Browse files
committed
Introduce Policy custom resource
1 parent 85f1637 commit f4edca3

23 files changed

Lines changed: 1738 additions & 24 deletions

File tree

charts/fleet-crd/templates/crds.yaml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10187,6 +10187,167 @@ spec:
1018710187
---
1018810188
apiVersion: apiextensions.k8s.io/v1
1018910189
kind: CustomResourceDefinition
10190+
metadata:
10191+
annotations:
10192+
controller-gen.kubebuilder.io/version: v0.21.0
10193+
name: policies.fleet.cattle.io
10194+
spec:
10195+
group: fleet.cattle.io
10196+
names:
10197+
kind: Policy
10198+
listKind: PolicyList
10199+
plural: policies
10200+
singular: policy
10201+
scope: Namespaced
10202+
versions:
10203+
- name: v1alpha1
10204+
schema:
10205+
openAPIV3Schema:
10206+
description: "Policy restricts what GitRepo, HelmOp, and Bundle resources\
10207+
\ in the same\nnamespace may do. Enforced at three points in the controller\
10208+
\ stack:\n\n - GitRepo reconciler: validates and applies defaults before\
10209+
\ producing a Bundle.\n - HelmOp reconciler: validates and applies defaults\
10210+
\ before producing a Bundle.\n - Bundle reconciler: validates only (fail-only)\
10211+
\ before producing BundleDeployments.\n\nTop-level fields are checked\
10212+
\ by all three reconcilers.\nSub-object fields (gitRepo, helmOp) are only\
10213+
\ read by their respective reconciler.\nDefault* fields inside sub-objects\
10214+
\ are applied before top-level validators run.\n\nMultiple Policy objects\
10215+
\ in the same namespace are aggregated with OR/union\nsemantics, sorted\
10216+
\ by name for determinism."
10217+
properties:
10218+
allowedServiceAccounts:
10219+
description: 'AllowedServiceAccounts lists service accounts that may
10220+
be used.
10221+
10222+
If non-empty, the ServiceAccount must appear in this list.
10223+
10224+
When RequireServiceAccount is also true, an empty ServiceAccount is
10225+
10226+
rejected regardless of this list.'
10227+
items:
10228+
type: string
10229+
nullable: true
10230+
type: array
10231+
apiVersion:
10232+
description: 'APIVersion defines the versioned schema of this representation
10233+
of an object.
10234+
10235+
Servers should convert recognized schemas to the latest internal value,
10236+
and
10237+
10238+
may reject unrecognized values.
10239+
10240+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
10241+
type: string
10242+
gitRepo:
10243+
description: GitRepo contains restrictions and defaults applied only
10244+
by the GitRepo reconciler.
10245+
properties:
10246+
allowedClientSecretNames:
10247+
description: 'AllowedClientSecretNames lists client secret names
10248+
that GitRepo objects
10249+
10250+
may reference.'
10251+
items:
10252+
type: string
10253+
nullable: true
10254+
type: array
10255+
allowedRepoPatterns:
10256+
description: 'AllowedRepoPatterns is a list of regex patterns restricting
10257+
the Repo
10258+
10259+
field of GitRepo objects.'
10260+
items:
10261+
type: string
10262+
nullable: true
10263+
type: array
10264+
defaultClientSecretName:
10265+
description: 'DefaultClientSecretName is applied to GitRepo objects
10266+
whose
10267+
10268+
ClientSecretName is empty.'
10269+
type: string
10270+
defaultServiceAccount:
10271+
description: 'DefaultServiceAccount is applied to GitRepo objects
10272+
whose ServiceAccount
10273+
10274+
is empty, before the top-level RequireServiceAccount check runs.'
10275+
type: string
10276+
type: object
10277+
helmOp:
10278+
description: HelmOp contains restrictions and defaults applied only
10279+
by the HelmOp reconciler.
10280+
properties:
10281+
allowedChartPatterns:
10282+
description: 'AllowedChartPatterns is a list of regex patterns restricting
10283+
the
10284+
10285+
spec.helm.chart field of HelmOp objects.'
10286+
items:
10287+
type: string
10288+
nullable: true
10289+
type: array
10290+
allowedHelmRepoPatterns:
10291+
description: 'AllowedHelmRepoPatterns is a list of regex patterns
10292+
restricting the
10293+
10294+
spec.helm.repo field of HelmOp objects.'
10295+
items:
10296+
type: string
10297+
nullable: true
10298+
type: array
10299+
allowedHelmSecretNames:
10300+
description: 'AllowedHelmSecretNames lists credential secret names
10301+
that HelmOp objects
10302+
10303+
may reference.'
10304+
items:
10305+
type: string
10306+
nullable: true
10307+
type: array
10308+
defaultHelmSecretName:
10309+
description: 'DefaultHelmSecretName is applied to HelmOp objects
10310+
whose HelmSecretName
10311+
10312+
is empty.'
10313+
type: string
10314+
defaultServiceAccount:
10315+
description: 'DefaultServiceAccount is applied to HelmOp objects
10316+
whose ServiceAccount
10317+
10318+
is empty, before the top-level RequireServiceAccount check runs.'
10319+
type: string
10320+
type: object
10321+
kind:
10322+
description: 'Kind is a string value representing the REST resource
10323+
this object represents.
10324+
10325+
Servers may infer this from the endpoint the client submits requests
10326+
to.
10327+
10328+
Cannot be updated.
10329+
10330+
In CamelCase.
10331+
10332+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
10333+
type: string
10334+
metadata:
10335+
type: object
10336+
requireServiceAccount:
10337+
description: 'RequireServiceAccount, when true, rejects any GitRepo,
10338+
HelmOp, or Bundle
10339+
10340+
whose ServiceAccount is empty after any defaulting has been applied.
10341+
10342+
Combine with AllowedServiceAccounts to also restrict which account
10343+
is used.'
10344+
type: boolean
10345+
type: object
10346+
served: true
10347+
storage: true
10348+
---
10349+
apiVersion: apiextensions.k8s.io/v1
10350+
kind: CustomResourceDefinition
1019010351
metadata:
1019110352
annotations:
1019210353
controller-gen.kubebuilder.io/version: v0.21.0

charts/fleet/templates/rbac_gitjob.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ rules:
4141
- "fleet.cattle.io"
4242
resources:
4343
- "gitreporestrictions"
44+
- "policies"
4445
verbs:
4546
- list
4647
- get

charts/fleet/templates/rbac_helmops.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ rules:
2525
- "helmops/status"
2626
verbs:
2727
- "*"
28+
- apiGroups:
29+
- "fleet.cattle.io"
30+
resources:
31+
- "policies"
32+
verbs:
33+
- list
34+
- get
35+
- watch
2836
- apiGroups:
2937
- "fleet.cattle.io"
3038
resources:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: GitRepo
2+
apiVersion: fleet.cattle.io/v1alpha1
3+
metadata:
4+
name: {{ .Name }}
5+
spec:
6+
repo: https://github.com/rancher/fleet-test-data
7+
branch: master
8+
paths:
9+
- simple
10+
targetNamespace: {{ .TargetNamespace }}
11+
serviceAccount: {{ .ServiceAccount }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: fleet.cattle.io/v1alpha1
2+
kind: HelmOp
3+
metadata:
4+
name: {{ .Name }}
5+
namespace: {{ .Namespace }}
6+
spec:
7+
helm:
8+
repo: {{.Repo}}
9+
chart: {{.Chart}}
10+
version: "{{.Version}}"
11+
namespace: {{ .Namespace }}
12+
{{- if ne .ServiceAccount "" }}
13+
serviceAccount: {{ .ServiceAccount }}
14+
{{- end }}
15+
{{- if ne .HelmSecretName "" }}
16+
helmSecretName: {{ .HelmSecretName }}
17+
{{- end }}
18+
targets:
19+
- clusterSelector: {}

0 commit comments

Comments
 (0)