Skip to content
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

Expose OPENSHIFT_CLUSTER_NAME as an env variable #2899

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danilo-gemoli
Copy link

Description

Expose the name of the cluster the operator is running on:

$ oc get infrastructure/cluster -o json | jq .status.infrastructureName

as an environment variable OPENSHIFT_CLUSTER_NAME on the collector container.
The previous major release v5.x of the operator used to set the cluster name as the default value of the groupPrefix field on the ClusterLogForwarder:

apiVersion: logging.openshift.io
kind: ClusterLogForwarder
spec:
  outputs:
  - type: cloudwatch
    cloudwatch:
      groupPrefix: ...

check the validation function here.
As far as I'm able to understand, that's not the case anymore in v6.x.
The old behavior was pretty convenient for a cluster admin because, with no configuration at all, it was possible to give meaningful names to log groups in AWS CloudWatch.
By exposing OPENSHIFT_CLUSTER_NAME it would allowed to mimic it once again:

apiVersion: observability.openshift.io
kind: ClusterLogForwarder
spec:
  outputs:
  - type: cloudwatch
    cloudwatch:
      groupName: '{ get_env_var("OPENSHIFT_CLUSTER_NAME") + .log_type || "noname" }'

/cc @jcantrill
/assign @jcantrill

Copy link
Contributor

openshift-ci bot commented Dec 6, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: danilo-gemoli
Once this PR has been reviewed and has the lgtm label, please assign jcantrill for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

openshift-ci bot commented Dec 6, 2024

@danilo-gemoli: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@cahartma
Copy link
Contributor

cahartma commented Dec 9, 2024

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 9, 2024
@cahartma
Copy link
Contributor

cahartma commented Dec 9, 2024

The templating logic should be restricted to object path, as it currently is. If we want to expose this var, we should implement a specific way of using it. The current function may be able to be adopted, but I would not feel comfortable just adding this var and env "injection" off-hand. QE should also be involved in this decision. cc: @anpingli

@cahartma
Copy link
Contributor

cahartma commented Dec 9, 2024

I suggest we discuss further in either a new Jira in the LOG project (@danilo-gemoli), or separate meeting where we can discuss and update this PR.

@anpingli
Copy link

anpingli commented Dec 11, 2024

@danilo-gemoli Test failed using your PR.

# clusterlogforwarders.observability.openshift.io "cloudwatch" was not valid:
# * spec.outputs[0].cloudwatch.groupName: Invalid value: "{ get_env_var(\"OPENSHIFT_CLUSTER_NAME\") + .log_type||\"missing\"}": spec.outputs[0].cloudwatch.groupName in body should match '^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$'

My CLF:

apiVersion: observability.openshift.io/v1
kind: ClusterLogForwarder
metadata:
  creationTimestamp: "2024-12-12T01:39:55Z"
  generation: 3
  name: cloudwatch
  namespace: openshift-logging
  resourceVersion: "66764"
  uid: e80cb1e2-b9fa-4d8b-98bd-a7c3253761b5
spec:
  managementState: Managed
  outputs:
  - cloudwatch:
      authentication:
        awsAccessKey:
          keyId:
            key: aws_access_key_id
            secretName: cloudwatch-credentials
          keySecret:
            key: aws_secret_access_key
            secretName: cloudwatch-credentials
        type: awsAccessKey
      groupName: '{ get_env_var("OPENSHIFT_CLUSTER_NAME") + .log_type||"missing"}'
      region: us-east-2
      tuning: {}
    name: cloudwatch
    type: cloudwatch
  pipelines:
  - inputRefs:
    - application
    - infrastructure
    name: cloudwatch
    outputRefs:
    - cloudwatch
  serviceAccount:
    name: logcollector

Question:
Why not set the cluster name directly in groupName? provide the cluster-name directly is easier than this Env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants