PolicyGenTemplate
自定义资源定义 (CRD) 告诉PolicyGen
策略生成器在集群配置中包含哪些自定义资源 (CR),如何将 CR 组合到生成的策略中,以及这些 CR 中哪些项目需要使用覆盖内容更新。
以下示例显示从ztp-site-generate
参考容器中提取的PolicyGenTemplate
CR (common-du-ranGen.yaml
)。common-du-ranGen.yaml
文件定义了两个 Red Hat Advanced Cluster Management (RHACM) 策略。这些策略管理一系列配置 CR,每个 CR 都有一个唯一的policyName
值。common-du-ranGen.yaml
创建单个放置绑定和放置规则,以根据spec.bindingRules
部分中列出的标签将策略绑定到集群。
PolicyGenTemplate CR 示例 - common-ranGen.yaml
apiVersion: ran.openshift.io/v1
kind: PolicyGenTemplate
metadata:
name: "common-latest"
namespace: "ztp-common"
spec:
bindingRules:
common: "true" (1)
du-profile: "latest"
sourceFiles: (2)
- fileName: SriovSubscriptionNS.yaml
policyName: "subscriptions-policy"
- fileName: SriovSubscriptionOperGroup.yaml
policyName: "subscriptions-policy"
- fileName: SriovSubscription.yaml
policyName: "subscriptions-policy"
- fileName: SriovOperatorStatus.yaml
policyName: "subscriptions-policy"
- fileName: PtpSubscriptionNS.yaml
policyName: "subscriptions-policy"
- fileName: PtpSubscriptionOperGroup.yaml
policyName: "subscriptions-policy"
- fileName: PtpSubscription.yaml
policyName: "subscriptions-policy"
- fileName: PtpOperatorStatus.yaml
policyName: "subscriptions-policy"
- fileName: ClusterLogNS.yaml
policyName: "subscriptions-policy"
- fileName: ClusterLogOperGroup.yaml
policyName: "subscriptions-policy"
- fileName: ClusterLogSubscription.yaml
policyName: "subscriptions-policy"
- fileName: ClusterLogOperatorStatus.yaml
policyName: "subscriptions-policy"
- fileName: StorageNS.yaml
policyName: "subscriptions-policy"
- fileName: StorageOperGroup.yaml
policyName: "subscriptions-policy"
- fileName: StorageSubscription.yaml
policyName: "subscriptions-policy"
- fileName: StorageOperatorStatus.yaml
policyName: "subscriptions-policy"
- fileName: DefaultCatsrc.yaml (3)
policyName: "config-policy" (4)
metadata:
name: redhat-operators-disconnected
spec:
displayName: disconnected-redhat-operators
image: registry.example.com:5000/disconnected-redhat-operators/disconnected-redhat-operator-index:v4.9
- fileName: DisconnectedICSP.yaml
policyName: "config-policy"
spec:
repositoryDigestMirrors:
- mirrors:
- registry.example.com:5000
source: registry.redhat.io
1 |
common: "true" 将策略应用于具有此标签的所有集群。 |
2 |
sourceFiles 下列出的文件为已安装的集群创建 Operator 策略。 |
3 |
DefaultCatsrc.yaml 为断开连接的注册表配置目录源。 |
4 |
policyName: "config-policy" 配置 Operator 订阅。OperatorHub CR 禁用默认值,此 CR 将redhat-operators 替换为指向断开连接的注册表的CatalogSource CR。 |
可以使用任意数量的包含 CR 来构建PolicyGenTemplate
CR。在中心集群中应用以下示例 CR 以生成包含单个 CR 的策略
apiVersion: ran.openshift.io/v1
kind: PolicyGenTemplate
metadata:
name: "group-du-sno"
namespace: "ztp-group"
spec:
bindingRules:
group-du-sno: ""
mcp: "master"
sourceFiles:
- fileName: PtpConfigSlave.yaml
policyName: "config-policy"
metadata:
name: "du-ptp-slave"
spec:
profile:
- name: "slave"
interface: "ens5f0"
ptp4lOpts: "-2 -s --summary_interval -4"
phc2sysOpts: "-a -r -n 24"
以源文件PtpConfigSlave.yaml
为例,该文件定义了PtpConfig
CR。为PtpConfigSlave
示例生成的策略名为group-du-sno-config-policy
。在生成的group-du-sno-config-policy
中定义的PtpConfig
CR 名为du-ptp-slave
。PtpConfigSlave.yaml
中定义的spec
与源文件中定义的其他spec
项目一起放在du-ptp-slave
下。
以下示例显示group-du-sno-config-policy
CR
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: group-du-ptp-config-policy
namespace: groups-sub
annotations:
policy.open-cluster-management.io/categories: CM Configuration Management
policy.open-cluster-management.io/controls: CM-2 Baseline Configuration
policy.open-cluster-management.io/standards: NIST SP 800-53
spec:
remediationAction: inform
disabled: false
policy-templates:
- objectDefinition:
apiVersion: policy.open-cluster-management.io/v1
kind: ConfigurationPolicy
metadata:
name: group-du-ptp-config-policy-config
spec:
remediationAction: inform
severity: low
namespaceselector:
exclude:
- kube-*
include:
- '*'
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: ptp.openshift.io/v1
kind: PtpConfig
metadata:
name: du-ptp-slave
namespace: openshift-ptp
spec:
recommend:
- match:
- nodeLabel: node-role.kubernetes.io/worker-du
priority: 4
profile: slave
profile:
- interface: ens5f0
name: slave
phc2sysOpts: -a -r -n 24
ptp4lConf: |
[global]
#
# Default Data Set
#
twoStepFlag 1
slaveOnly 0
priority1 128
priority2 128
domainNumber 24