-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a policy to automatically import discovered ROSA clusters #470
Merged
openshift-merge-bot
merged 1 commit into
open-cluster-management-io:main
from
gparvin:rosa-autoimport
May 17, 2024
+102
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
101 changes: 101 additions & 0 deletions
101
community/CM-Configuration-Management/policy-rosa-autoimport.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: Policy | ||
metadata: | ||
name: policy-rosa-autoimport | ||
annotations: | ||
policy.open-cluster-management.io/standards: NIST SP 800-53 | ||
policy.open-cluster-management.io/categories: CM Configuration Management | ||
policy.open-cluster-management.io/controls: CM-2 Baseline Configuration | ||
policy.open-cluster-management.io/description: Discovered clusters that are of | ||
type ROSA can be automatically imported into ACM as managed clusters. This | ||
policy helps you select those managed clusters and configure them so the import | ||
will happen. If you do not want all of your ROSA clusters to be automatically | ||
imported, you can configure filters or add an annotation. | ||
spec: | ||
remediationAction: inform | ||
disabled: false | ||
policy-templates: | ||
- objectDefinition: | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: policy-rosa-autoimport | ||
spec: | ||
remediationAction: inform | ||
severity: low | ||
object-templates-raw: | | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: discovery-config | ||
namespace: open-cluster-management-global-set | ||
data: | ||
rosa-filter: "" | ||
{{- /* find the ROSA DiscoveredClusters */ -}} | ||
{{- range $dc := (lookup "discovery.open-cluster-management.io/v1" "DiscoveredCluster" "" "").items }} | ||
{{- /* Check for the flag that indicates the import should be skipped */ -}} | ||
{{- $skip := "false" -}} | ||
{{- range $key, $value := $dc.metadata.annotations }} | ||
{{- if and (eq $key "discovery.open-cluster-management.io/previously-auto-imported") | ||
(eq $value "true") }} | ||
{{- $skip = "true" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- /* if the type is ROSA and the status is Active */ -}} | ||
{{- if and (eq $dc.spec.status "Active") | ||
(contains (fromConfigMap "open-cluster-management-global-set" "discovery-config" "rosa-filter") $dc.spec.displayName) | ||
(eq $dc.spec.type "ROSA") | ||
(eq $skip "false") }} | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: discovery.open-cluster-management.io/v1 | ||
kind: DiscoveredCluster | ||
metadata: | ||
name: {{ $dc.metadata.name }} | ||
namespace: {{ $dc.metadata.namespace }} | ||
spec: | ||
importAsManagedCluster: true | ||
{{- end }} | ||
{{- end }} | ||
- objectDefinition: | ||
apiVersion: policy.open-cluster-management.io/v1 | ||
kind: ConfigurationPolicy | ||
metadata: | ||
name: policy-rosa-managedcluster-status | ||
spec: | ||
remediationAction: inform | ||
severity: low | ||
object-templates-raw: | | ||
{{- /* Use the same DiscoveredCluster list to check ManagedCluster status */ -}} | ||
{{- range $dc := (lookup "discovery.open-cluster-management.io/v1" "DiscoveredCluster" "" "").items }} | ||
{{- /* Check for the flag that indicates the import should be skipped */ -}} | ||
{{- $skip := "false" -}} | ||
{{- range $key, $value := $dc.metadata.annotations }} | ||
{{- if and (eq $key "discovery.open-cluster-management.io/previously-auto-imported") | ||
(eq $value "true") }} | ||
{{- $skip = "true" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- /* if the type is ROSA and the status is Active */ -}} | ||
{{- if and (eq $dc.spec.status "Active") | ||
(contains (fromConfigMap "open-cluster-management-global-set" "discovery-config" "rosa-filter") $dc.spec.displayName) | ||
(eq $dc.spec.type "ROSA") | ||
(eq $skip "false") }} | ||
- complianceType: musthave | ||
objectDefinition: | ||
apiVersion: cluster.open-cluster-management.io/v1 | ||
kind: ManagedCluster | ||
metadata: | ||
name: {{ $dc.spec.displayName }} | ||
namespace: {{ $dc.spec.displayName }} | ||
annotations: | ||
cluster.open-cluster-management.io/clusterset: default | ||
status: | ||
conditions: | ||
- type: ManagedClusterAvailable | ||
status: "True" | ||
{{- end }} | ||
{{- end }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than skip if
discovery.open-cluster-management.io/previously-auto-imported
is set, it might be cool to just make the clusterset annotation conditional on this so that the policy can still report on the status after it's been imported but still allow the user to change the clusterset.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ManagedCluster resource won't exist, it will have been deleted after being detached.