Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _topic_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1377,6 +1377,8 @@ Topics:
File: osdk-working-bundle-images
- Name: Validating Operators using the scorecard
File: osdk-scorecard
- Name: High-availability or single node cluster detection and support
File: osdk-ha-sno
- Name: Configuring built-in monitoring with Prometheus
File: osdk-monitoring-prometheus
- Name: Configuring leader election
Expand Down
38 changes: 38 additions & 0 deletions modules/osdk-ha-sno-api-examples.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Module included in the following assemblies:
//
// * operators/operator_sdk/osdk-ha-sno.adoc

[id="osdk-ha-sno-api-examples_{context}"]
= Example API usage in Operator projects

As an Operator author, you can update your Operator project to access the Infrastructure API by using normal Kubernetes constructs and the `controller-runtime` library, as shown in the following examples:

.`controller-runtime` library example
[source,go]
----
// Simple query
nn := types.NamespacedName{
Name: "cluster",
}
infraConfig := &configv1.Infrastructure{}
err = crClient.Get(context.Background(), nn, infraConfig)
if err != nil {
return err
}
fmt.Printf("using crclient: %v\n", infraConfig.Status.ControlPlaneTopology)
fmt.Printf("using crclient: %v\n", infraConfig.Status.InfrastructureTopology)
----

.Kubernetes constructs example
[source,go]
----
operatorConfigInformer := configinformer.NewSharedInformerFactoryWithOptions(configClient, 2*time.Second)
infrastructureLister = operatorConfigInformer.Config().V1().Infrastructures().Lister()
infraConfig, err := configClient.ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
if err != nil {
return err
}
// fmt.Printf("%v\n", infraConfig)
fmt.Printf("%v\n", infraConfig.Status.ControlPlaneTopology)
fmt.Printf("%v\n", infraConfig.Status.InfrastructureTopology)
----
18 changes: 18 additions & 0 deletions modules/osdk-ha-sno-api.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Module included in the following assemblies:
//
// * operators/operator_sdk/osdk-ha-sno.adoc

[id="osdk-ha-sno-api_{context}"]
= About the cluster high-availability mode API

{product-title} provides a cluster high-availability mode API that can be used by Operators to help detect infrastructure topology. The Infrastructure API holds cluster-wide information regarding infrastructure. Operators managed by Operator Lifecycle Manager (OLM) can use the Infrastructure API if they need to configure an Operand or managed workload differently based on the high-availability mode.

In the Infrastructure API, the `infrastructureTopology` status expresses the expectations for infrastructure services that do not run on control plane nodes, usually indicated by a node selector for a `role` value other than `master`. The `controlPlaneTopology` status expresses the expectations for Operands that normally run on control plane nodes.

The default setting for either status is `HighlyAvailable`, which represents the behavior Operators have in multiple node clusters. The `SingleReplica` setting is used in single node clusters, also known as Single Node OpenShift (SNO), and indicates that Operators should not configure their Operands for high-availability operation.

The {product-title} installer sets the `controlPlaneTopology` and `infrastructureTopology` status fields based on the replica counts for the cluster when it is created, according to the following rules:

* When the control plane replica count is less than 3, the `controlPlaneTopology` status is set to `SingleReplica`. Otherwise, it is set to `HighlyAvailable`.
* When the worker replica count is 0, the control plane nodes are also configured as workers. Therefore, the `infrastructureTopology` status will be the same as the `controlPlaneTopology` status.
* When the worker replica count is 1, the `infrastructureTopology` is set to `SingleReplica`. Otherwise, it is set to `HighlyAvailable`.
13 changes: 13 additions & 0 deletions operators/operator_sdk/osdk-ha-sno.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[id="osdk-ha-sno"]
= High-availability or single node cluster detection and support
include::modules/common-attributes.adoc[]
:context: osdk-ha-sno

toc::[]

An {product-title} cluster can be configured in high-availability (HA) mode, which uses multiple nodes, or in non-HA mode, which uses a single node. A single node cluster, also known as Single Node OpenShift (SNO), is likely to have more conservative resource constraints. Therefore, it is important that Operators installed on a single node cluster can adjust accordingly and still run well.

By accessing the cluster high-availability mode API provided in {product-title}, Operator authors can use the Operator SDK to enable their Operator to detect a cluster's infrastructure topology, either HA or non-HA mode. Custom Operator logic can be developed that uses the detected cluster topology to automatically switch the resource requirements, both for the Operator and for any Operands or workloads it manages, to a profile that best fits the topology.

include::modules/osdk-ha-sno-api.adoc[leveloffset=+1]
include::modules/osdk-ha-sno-api-examples.adoc[leveloffset=+1]