PolicyGenerator
自定义资源定义 (CRD) 告诉PolicyGen
策略生成器要将哪些自定义资源 (CR) 包含在集群配置中,如何将 CR 组合到生成的策略中,以及需要使用覆盖内容更新这些 CR 中的哪些项目。
以下示例显示了从ztp-site-generate
参考容器中提取的PolicyGenerator
CR (acm-common-du-ranGen.yaml
)。acm-common-du-ranGen.yaml
文件定义了两个 Red Hat Advanced Cluster Management (RHACM) 策略。这些策略管理一系列配置 CR,每个 CR 的policyName
的唯一值对应一个。acm-common-du-ranGen.yaml
创建单个放置绑定和放置规则,以根据policyDefaults.placement.labelSelector
部分中列出的标签将策略绑定到集群。
PolicyGenerator CR 示例 - acm-common-ranGen.yaml
apiVersion: policy.open-cluster-management.io/v1
kind: PolicyGenerator
metadata:
name: common-latest
placementBindingDefaults:
name: common-latest-placement-binding (1)
policyDefaults:
namespace: ztp-common
placement:
labelSelector:
matchExpressions:
- key: common
operator: In
values:
- "true"
- key: du-profile
operator: In
values:
- latest
remediationAction: inform
severity: low
namespaceSelector:
exclude:
- kube-*
include:
- '*'
evaluationInterval:
compliant: 10m
noncompliant: 10s
policies:
- name: common-latest-config-policy
policyAnnotations:
ran.openshift.io/ztp-deploy-wave: "1"
manifests:
- path: source-crs/ReduceMonitoringFootprint.yaml
- path: source-crs/DefaultCatsrc.yaml (2)
patches:
- metadata:
name: redhat-operators-disconnected
spec:
displayName: disconnected-redhat-operators
image: registry.example.com:5000/disconnected-redhat-operators/disconnected-redhat-operator-index:v4.9
- path: source-crs/DisconnectedICSP.yaml
patches:
- spec:
repositoryDigestMirrors:
- mirrors:
- registry.example.com:5000
source: registry.redhat.io
- name: common-latest-subscriptions-policy
policyAnnotations:
ran.openshift.io/ztp-deploy-wave: "2"
manifests: (3)
- path: source-crs/SriovSubscriptionNS.yaml
- path: source-crs/SriovSubscriptionOperGroup.yaml
- path: source-crs/SriovSubscription.yaml
- path: source-crs/SriovOperatorStatus.yaml
- path: source-crs/PtpSubscriptionNS.yaml
- path: source-crs/PtpSubscriptionOperGroup.yaml
- path: source-crs/PtpSubscription.yaml
- path: source-crs/PtpOperatorStatus.yaml
- path: source-crs/ClusterLogNS.yaml
- path: source-crs/ClusterLogOperGroup.yaml
- path: source-crs/ClusterLogSubscription.yaml
- path: source-crs/ClusterLogOperatorStatus.yaml
- path: source-crs/StorageNS.yaml
- path: source-crs/StorageOperGroup.yaml
- path: source-crs/StorageSubscription.yaml
- path: source-crs/StorageOperatorStatus.yaml
1 |
将策略应用于具有此标签的所有集群。 |
2 |
DefaultCatsrc.yaml 文件包含断开连接的注册表和相关的注册表配置详细信息的目录源。 |
3 |
policies.manifests 下列出的文件为已安装的集群创建 Operator 策略。 |
可以使用任意数量的包含的 CR 来构造PolicyGenerator
CR。在中心集群中应用以下示例 CR 以生成包含单个 CR 的策略
apiVersion: policy.open-cluster-management.io/v1
kind: PolicyGenerator
metadata:
name: group-du-sno
placementBindingDefaults:
name: group-du-sno-placement-binding
policyDefaults:
namespace: ztp-group
placement:
labelSelector:
matchExpressions:
- key: group-du-sno
operator: Exists
remediationAction: inform
severity: low
namespaceSelector:
exclude:
- kube-*
include:
- '*'
evaluationInterval:
compliant: 10m
noncompliant: 10s
policies:
- name: group-du-sno-config-policy
policyAnnotations:
ran.openshift.io/ztp-deploy-wave: '10'
manifests:
- path: source-crs/PtpConfigSlave-MCP-master.yaml
patches:
- metadata: null
name: du-ptp-slave
namespace: openshift-ptp
annotations:
ran.openshift.io/ztp-deploy-wave: '10'
spec:
profile:
- name: slave
interface: $interface
ptp4lOpts: '-2 -s'
phc2sysOpts: '-a -r -n 24'
ptpSchedulingPolicy: SCHED_FIFO
ptpSchedulingPriority: 10
ptpSettings:
logReduce: 'true'
ptp4lConf: |
[global]
#
# Default Data Set
#
twoStepFlag 1
slaveOnly 1
priority1 128
priority2 128
domainNumber 24
#utc_offset 37
clockClass 255
clockAccuracy 0xFE
offsetScaledLogVariance 0xFFFF
free_running 0
freq_est_interval 1
dscp_event 0
dscp_general 0
dataset_comparison G.8275.x
G.8275.defaultDS.localPriority 128
#
# Port Data Set
#
logAnnounceInterval -3
logSyncInterval -4
logMinDelayReqInterval -4
logMinPdelayReqInterval -4
announceReceiptTimeout 3
syncReceiptTimeout 0
delayAsymmetry 0
fault_reset_interval -4
neighborPropDelayThresh 20000000
masterOnly 0
G.8275.portDS.localPriority 128
#
# Run time options
#
assume_two_step 0
logging_level 6
path_trace_enabled 0
follow_up_info 0
hybrid_e2e 0
inhibit_multicast_service 0
net_sync_monitor 0
tc_spanning_tree 0
tx_timestamp_timeout 50
unicast_listen 0
unicast_master_table 0
unicast_req_duration 3600
use_syslog 1
verbose 0
summary_interval 0
kernel_leap 1
check_fup_sync 0
clock_class_threshold 7
#
# Servo Options
#
pi_proportional_const 0.0
pi_integral_const 0.0
pi_proportional_scale 0.0
pi_proportional_exponent -0.3
pi_proportional_norm_max 0.7
pi_integral_scale 0.0
pi_integral_exponent 0.4
pi_integral_norm_max 0.3
step_threshold 2.0
first_step_threshold 0.00002
max_frequency 900000000
clock_servo pi
sanity_freq_limit 200000000
ntpshm_segment 0
#
# Transport options
#
transportSpecific 0x0
ptp_dst_mac 01:1B:19:00:00:00
p2p_dst_mac 01:80:C2:00:00:0E
udp_ttl 1
udp6_scope 0x0E
uds_address /var/run/ptp4l
#
# Default interface options
#
clock_type OC
network_transport L2
delay_mechanism E2E
time_stamping hardware
tsproc_mode filter
delay_filter moving_median
delay_filter_length 10
egressLatency 0
ingressLatency 0
boundary_clock_jbod 0
#
# Clock description
#
productDescription ;;
revisionData ;;
manufacturerIdentity 00:00:00
userDescription ;
timeSource 0xA0
recommend:
- profile: slave
priority: 4
match:
- nodeLabel: node-role.kubernetes.io/master
以源文件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: PolicyGenerator
metadata:
name: du-upgrade
placementBindingDefaults:
name: du-upgrade-placement-binding
policyDefaults:
namespace: ztp-group-du-sno
placement:
labelSelector:
matchExpressions:
- key: group-du-sno
operator: Exists
remediationAction: inform
severity: low
namespaceSelector:
exclude:
- kube-*
include:
- '*'
evaluationInterval:
compliant: 10m
noncompliant: 10s
policies:
- name: du-upgrade-operator-catsrc-policy
policyAnnotations:
ran.openshift.io/ztp-deploy-wave: "1"
manifests:
- path: source-crs/DefaultCatsrc.yaml
patches:
- metadata:
name: redhat-operators
spec:
displayName: Red Hat Operators Catalog
image: registry.example.com:5000/olm/redhat-operators:v4.14
updateStrategy:
registryPoll:
interval: 1h
status:
connectionState:
lastObservedState: READY