Skip to content

Commit

Permalink
Merge pull request #2375 from replicatedhq/ne-ec-repl-example
Browse files Browse the repository at this point in the history
Add EC distro check example
  • Loading branch information
paigecalvert committed May 24, 2024
2 parents fb6078f + e182033 commit 6bdaaaa
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 3 deletions.
58 changes: 58 additions & 0 deletions docs/partials/template-functions/_ne-comparison.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
In the example below, the `ingress_type` field is displayed on the **Config** page only when the distribution of the cluster is _not_ [Replicated embedded cluster](/vendor/embedded-overview). This ensures that only users deploying to their own existing cluster are able to select the method for ingress.

The following example uses:
* KOTS [Distribution](/reference/template-functions-static-context#distribution) template function to return the Kubernetes distribution of the cluster where KOTS is running
* [ne](https://pkg.go.dev/text/template#hdr-Functions) (_not equal_) Go binary operator to compare the rendered value of the Distribution template function to a string, then return `true` if the values are not equal to one another

```yaml
apiVersion: kots.io/v1beta1
kind: Config
metadata:
name: config
spec:
groups:
# Ingress settings
- name: ingress_settings
title: Ingress Settings
description: Configure Ingress
items:
- name: ingress_type
title: Ingress Type
help_text: |
Select how traffic will ingress to the appliction.
type: select_one
items:
- name: ingress_controller
title: Ingress Controller
- name: load_balancer
title: Load Balancer
default: "ingress_controller"
required: true
when: 'repl{{ ne Distribution "embedded-cluster" }}'
# Database settings
- name: database_settings
title: Database
items:
- name: postgres_type
help_text: Would you like to use an embedded postgres instance, or connect to an external instance that you manage?
type: select_one
title: Postgres
default: embedded_postgres
items:
- name: embedded_postgres
title: Embedded Postgres
- name: external_postgres
title: External Postgres
```

The following image shows how the `ingress_type` field is hidden when the distribution of the cluster is `embedded-cluster`. Only the `postgres_type` item is displayed:

<img alt="Config page with a Postgres field" src="/images/config-example-distribution-not-ec.png" width="550px"/>

[View a larger version of this image](/images/config-example-distribution-not-ec.png)

Conversely, when the distribution of the cluster is not `embedded-cluster`, both fields are displayed:

<img alt="Config page with Ingress and Postgres fields" src="/images/config-example-distribution-not-ec-2.png" width="550px"/>

[View a larger version of this image](/images/config-example-distribution-not-ec-2.png)
2 changes: 1 addition & 1 deletion docs/partials/template-functions/_string-comparison.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The following example uses:
* KOTS [Distribution](/reference/template-functions-static-context#distribution) template function to return the Kubernetes distribution of the cluster where KOTS is running
* [eq](https://pkg.go.dev/text/template#hdr-Functions) Go binary operator to compare the rendered value of the Distribution template function to a string, then return the boolean truth of the comparison
* [eq](https://pkg.go.dev/text/template#hdr-Functions) (_equal_) Go binary operator to compare the rendered value of the Distribution template function to a string, then return the boolean truth of the comparison

```yaml
# KOTS Config custom resource
Expand Down
7 changes: 7 additions & 0 deletions docs/reference/template-functions-examples.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import IntegerComparison from "../partials/template-functions/_integer-comparison.mdx"
import StringComparison from "../partials/template-functions/_string-comparison.mdx"
import NeComparison from "../partials/template-functions/_ne-comparison.mdx"
import GoSprig from "../partials/template-functions/_go-sprig.mdx"
import UseCases from "../partials/template-functions/_use-cases.mdx"

Expand Down Expand Up @@ -78,6 +79,12 @@ A common use case for string comparison is to compare the rendered value of a KO

<StringComparison/>

### Not Equal To Comparison

It can be useful to compare the rendered value of a KOTS template function against another value to check if the two values are different. For example, you can conditionally show fields on the KOTS admin console **Config** page only when the Kubernetes distribution of the cluster where the application is deployed is _not_ [Replicated embedded cluster](/vendor/embedded-overview).

<NeComparison/>

### Logical AND Comparison

Logical comparisons such as AND, OR, and NOT can be used with KOTS template functions. A common use case for logical AND comparisons is to construct more complex conditional statements where it is necessary that two different conditions are both true.
Expand Down
20 changes: 20 additions & 0 deletions docs/reference/template-functions-static-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,15 @@ repl{{ TLSKeyFromCA "foo.com" "my_custom_cert" "bar.com" (list "10.0.0.1" "10.0.
func IsKurl() bool
```
IsKurl returns true if running within a kurl-based installation.
#### Detect kURL Installations
```yaml
repl{{ IsKurl }}
```
#### Detect Non-kURL Installations
```yaml
repl{{ not IsKurl }}
```
See [Functions](https://pkg.go.dev/text/template#hdr-Functions) in the Go documentation.
## Distribution
```go
Expand All @@ -440,9 +446,23 @@ Distribution returns the Kubernetes distribution detected. The possible return v
* openShift
* rke2
:::note
[IsKurl](#iskurl) can also be used to detect kURL instances.
:::
#### Detect the Distribution
```yaml
repl{{ Distribution }}
```
#### Equal To Comparison
```yaml
repl{{ eq Distribution "gke" }}
```
#### Not Equal To Comparison
```yaml
repl{{ ne Distribution "embedded-cluster" }}
```
See [Functions](https://pkg.go.dev/text/template#hdr-Functions) in the Go documentation.
## NodeCount
```go
Expand Down
11 changes: 9 additions & 2 deletions docs/vendor/config-screen-conditional.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import IntegerComparison from "../partials/template-functions/_integer-comparison.mdx"
import PropertyWhen from "../partials/config/_property-when.mdx"
import DistroCheck from "../partials/template-functions/_string-comparison.mdx"
import NeComparison from "../partials/template-functions/_ne-comparison.mdx"

# Using Conditional Statements in Configuration Fields

Expand Down Expand Up @@ -28,9 +29,15 @@ In the following example, the `when` properties use the [Distribution](/referenc

<DistroCheck/>

### kURL Cluster Check
### Embedded Cluster Distribution Check

It can be useful to show or hide configuration fields if the cluster was provisioned by Replicated kURL because kURL distributions often include add-ons to manage functionality such as ingress and storage. This means that kURL clusters frequently have fewer configuration options for the end user.
It can be useful to show or hide configuration fields if the distribution of the cluster is [Replicated embedded cluster](/vendor/embedded-overview) because you can include extensions in embedded cluster distributions to manage functionality such as ingress and storage. This means that embedded clusters frequently have fewer configuration options for the user.

<NeComparison/>

### kURL Distribution Check

It can be useful to show or hide configuration fields if the cluster was provisioned by Replicated kURL because kURL distributions often include add-ons to manage functionality such as ingress and storage. This means that kURL clusters frequently have fewer configuration options for the user.

In the following example, the `when` property of the `not_kurl` group uses the IsKurl template function to evaluate if the cluster was provisioned by kURL. For more information about the IsKurl template function, see [IsKurl](/reference/template-functions-static-context#iskurl) in _Static Context_.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6bdaaaa

Please sign in to comment.