Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Use OperatorPolicy to manage Kubernetes-native applications

May 14, 2024
Jacob Berger Justin Kulikauskas
Related topics:
KubernetesSecure Coding
Related products:
Red Hat Advanced Cluster Management for Kubernetes

Share:

    You can use the policy framework in Red Hat Advanced Cluster Management for Kubernetes (RHACM) to define and manage configurations of resources across a fleet of clusters. When packaged with the Operator Lifecycle Manager (OLM), Kubernetes-native applications become resources that you can manage, similar to the built-in resource types on a cluster. In the 2.10 release of RHACM, we are introducing a new kind of policy template, OperatorPolicy, as a tech preview feature which helps manage these specific types more completely and more easily.

    In this article, you’ll learn the basics of the OperatorPolicy, and you’ll see a demo about how to use it. Because this is a tech preview feature, we are looking forward to hearing your feedback about how we can improve these features for you.

    Update: this feature is generally available in the 2.11 release of RHACM, and introduces it with its new features. Learn more here.

    OperatorPolicy overview

    As a new kind of policy template, the primary way of distributing an OperatorPolicy to a cluster is by defining it inside a policy, just like ConfigurationPolicies. The policy can then be associated with a Placement and PlacementBinding in order to propagate it to a managed cluster. To learn more about this process, see our other posts. In this article, we will focus on a specific example of just the OperatorPolicy. See the following example:

    apiVersion: policy.open-cluster-management.io/v1beta1
    kind: OperatorPolicy
    metadata:
      name: quay-operator
    spec:
      remediationAction: inform
      severity: high
      complianceType: musthave
      operatorGroup: # optional
        name: quay-opgroup
        namespace: policy-blog
        targetNamespaces:
            - policy-blog
      subscription:
        channel: stable-3.10
        name: quay-operator
        namespace: policy-blog
        installPlanApproval: Manual
        source: redhat-operators
        sourceNamespace: openshift-marketplace
        startingCSV: quay-operator.v3.10.0
      versions:
        - quay-operator.v3.10.0

    Some of the spec fields should be familiar to users of ConfigurationPolicy. These fields have a similar purpose in an OperatorPolicy:

    • You can set the remediationAction field to inform or enforce. When set to enforce, the controller on the managed cluster can take actions to move the policy towards compliance. In particular, it can create resources or approve InstallPlans. When set to inform, the policy only observes and reports on the current status and does not take any actions on the cluster.
    • You can set the severity field can be set to low, medium, high, or critical.
    • The complianceType field currently only supports musthave, indicating the policy wants the operator described in the policy to exist.

    The remaining fields are specific to OperatorPolicy:

    • The operatorGroup field is optional, and is used to define details needed for the OperatorGroup. The configuration here limits the scope of the operator to a single namespace called policy-blog. For any fields that you want to put in the spec of an OperatorGroup, you can put in this field, in addition to the name and namespace. When this field is unset, the policy accepts any existing OperatorGroup in the namespace, and can create a default AllNamespaces group if the policy is being enforced. 
    • The subscription field defines the operator, generally specifying what the policy wants installed and where to look for updates. Any fields available on a Subscription spec can be set here. The example here is for a specific version of the quay-operator.
    • The versions field is optional, and takes a list of allowed versions of the operator. If not set, any version of the operator can be considered compliant. When this field is set, the installed version on the cluster must exactly match a version in the list in order for the policy to be compliant. When the policy is enforced, it approves updates to the operator that match a version in this list.

    Viewing the status during an upgrade

    Time to see an OperatorPolicy in action! Although the status of an OperatorPolicy is designed to be structured and readable directly by users, it’s helpful to view it in the RHACM console. After creating the example policy, we can view the related resources section in the web UI, as shown in Figure 1.

    The Related Resources table in the console, showing information about the Deployment, InstallPlan, and more.
    The Related Resources table for the OperatorPolicy shows the name and status of many objects relevant to an operator installation.
    Figure 1: The related resources table for the OperatorPolicy shows the name and status of many objects relevant to an operator installation.

    Because the remediationAction of the policy is set to inform, and the operator is not yet installed on the cluster, the policy is reported as “NonCompliant.” In the details, we can see that the Subscription and the OperatorGroup are currently missing, and those are both listed as reasons that the policy is NonCompliant. However, the CatalogSource used for the operator is present and healthy on the cluster. We can even click on that View YAML link to view more details about that resource on the managed cluster.

    By enforcing the policy, we can have the controller on the managed cluster create the Subscription that we want for the operator, and then the UI is updated; for example, see Figure 2.

    The Related Resources table in the console, displaying that the Subscription and Deployment have been created.
    The Related Resources table in the console updates based on the current state of resources in the cluster, showing what the enforced policy has done.
    Figure 2: the Related Resources table in the console updates based on the current state of resources in the cluster, showing what the enforced policy has done.

    We can see that the Subscription and OperatorGroup were created based on the content in the policy, and an initial InstallPlan has been completed. The policy also reports on the Deployment and ClusterServiceVersion for the operator, and although this is not demonstrated here, if the InstallPlan or the Deployment had an error, that information would be surfaced in the policy status. Again, we can use the View YAML links to view the full content of these resources on the managed cluster.

    The policy is still NonCompliant because there is an upgrade available for the operator. The policy controller does not automatically approve that new InstallPlan, because it does not match a version specified in the OperatorPolicy spec.versions list. In the UI, we can also view the policy's history (Figure 3).

    The compliance history table in the console, detailing the actions taken by the policy
    The history in the console can be used to understand the current status and what actions have been taken recently.
    Figure 3: the history in the console can be used to understand the current status and what actions have been taken recently.

    This view makes it clear that the initial installation of the operator succeeded to version "quay-operator.v3.10.0", and the policy waited for the operator deployment to become healthy before becoming Compliant. Soon after that, OLM created a new InstallPlan to update the operator to version "quay-operator.v3.10.4", at which point the policy became NonCompliant again.

    If we edit the policy to add this new version to the allowed spec.versions list, then the controller approves the InstallPlan for us. This process allows you to manage operator versions across many clusters, which might use different catalog sources, and therefore, have different versions available at different times. Approving individual InstallPlans like this would be very cumbersome with ConfigurationPolicies, likely requiring advanced templating and possibly not always working on all clusters. We hope that this feature provides you with a useful tool for more control than the usual "Automatic" option provided by OLM, without the burden of manually approving multiple InstallPlans across a fleet of clusters.

    After adding the new version to the policy, we can view the related resources again (Figure 4).

    The Related Resources table in the console, displaying that all objects are now compliant
    The Related Resources table in the console now shows that the state of the cluster matches what is desired by the policy.
    Figure 4: the Related Resources table in the console now shows that the state of the cluster matches what is desired by the policy.

    The policy is now Compliant. Notice that the "No Status" messages attached to the InstallPlans do not indicate that status information is missing. Instead, it refers to the fact that these InstallPlans do not affect the compliance of the policy. Previously completed or failed InstallPlans are usually retained for historical information and do not necessarily indicate the status of the current installation.

    Tech preview status

    As mentioned, the OperatorPolicy kind is available in Red Hat Advanced Cluster Management for Kubernetes 2.10 as a tech preview feature. Details in this article are likely to change as the feature continues to develop. In particular, we have already identified certain status messages that are more noisy than useful, and that different users could benefit from some additional options around available upgrade reporting. Few people would want to be paged out early in the morning for a NonCompliant OperatorPolicy just because a new version is available.

    We have several more features that we are hoping to implement in OperatorPolicy to make the process of installing and managing operators easier for new users, who might be less familiar with all the details and complexity of the Operator Lifecycle Manager. For Red Hat OpenShift users, we hope to integrate our Create Policy wizard with the operator catalog on the hub cluster, for better discovery of operators that can be installed.

    Anyone interested can view the design document/enhancement proposal in the community. We welcome any and all feedback!

    Last updated: January 15, 2025

    Related Posts

    • Installing Red Hat Advanced Cluster Management (ACM) for Kubernetes

    • Deploy an Operator via GitOps using Advanced Cluster Management

    • Migrating a namespace-scoped Operator to a cluster-scoped Operator

    • Skupper.io: Let your services communicate across Kubernetes clusters

    • Working with Kubernetes in Podman Desktop

    • 3 patterns for deploying Helm charts with Argo CD

    Recent Posts

    • How to run AI models in cloud development environments

    • How Trilio secures OpenShift virtual machines and containers

    • How to implement observability with Node.js and Llama Stack

    • How to encrypt RHEL images for Azure confidential VMs

    • How to manage RHEL virtual machines with Podman Desktop

    What’s up next?

    Read Operating OpenShift, a practical guide to running and operating OpenShift clusters more efficiently using a site reliability engineering (SRE) approach. Learn best practices and tools that can help reduce the effort of deploying a Kubernetes platform.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue