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

operator: Refactor CreateOrUpdateLokiStack handler #11592

Merged
merged 20 commits into from
Jan 12, 2024

Conversation

periklis
Copy link
Collaborator

@periklis periklis commented Jan 5, 2024

What this PR does / why we need it:
Refactor the CreateOrUpdateLokiStack handler to separate functions to re-instantiate readability.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
The gist is moving and isolating all internal packages code into the internal package itself for gateway, storage and rules. This enhances readability in the handler itself. In addition the internal package's public interface is down to 1 or max 2 functions (i.e. {gateway,storage,rules}.BuildOptions) and the use cases can be tested locally w/o the heavy handler setup code.

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • CHANGELOG.md updated
    • If the change is worth mentioning in the release notes, add add-to-release-notes label
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

cc @JoaoBraveCoding

@periklis periklis self-assigned this Jan 5, 2024
@periklis periklis requested review from xperimental and a team as code owners January 5, 2024 15:31
Copy link
Contributor

github-actions bot commented Jan 5, 2024

Trivy scan found the following vulnerabilities:

  • HIGH, Target: docker.io/grafana/loki:main-ee3cf4b (alpine 3.18.4), Type: alpine openssl: Incorrect cipher key and IV length processing in libcrypto3 v3.1.3-r0. Fixed in v3.1.4-r0
  • HIGH, Target: docker.io/grafana/loki:main-ee3cf4b (alpine 3.18.4), Type: alpine openssl: Incorrect cipher key and IV length processing in libssl3 v3.1.3-r0. Fixed in v3.1.4-r0
    \nTo see more details on these vulnerabilities, and how/where to fix them, please run docker build -t grafana/loki:main-ee3cf4b -f cmd/loki/Dockerfile .
    trivy i grafana/loki:main-ee3cf4b on your branch. If these were not introduced by your PR, please considering fixing them in via a subsequent PR. Thanks!

Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment but apart from that it does make CreateOrUpdateLokiStack simpler on the eyes

operator/internal/handlers/lokistack_create_or_update.go Outdated Show resolved Hide resolved
@periklis periklis force-pushed the refactor-lokistack-upsert-handler branch from 7fab92e to 900a5a1 Compare January 11, 2024 18:30
Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I like this version much more! Just a small comment but this is going in a great direction

operator/internal/handlers/internal/storage/storage.go Outdated Show resolved Hide resolved
)

var hashSeparator = []byte(",")

// ExtractSecret reads a k8s secret into a manifest object storage struct if valid.
func ExtractSecret(s *corev1.Secret, secretType lokiv1.ObjectStorageSecretType) (*storage.Options, error) {
func getSecret(ctx context.Context, k k8s.Client, stack *lokiv1.LokiStack) (*corev1.Secret, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about error handling, if we plan for this function to be used to fetch other secrets other than the object storage one then, we should also provide a way to configure the DegradedError struct.

I am however more of the opinion of changing the name of this function to be more specific and not allude to the idea of reusing it when we need to get secrets from k8s. Instead, we should create a new function for getting new secrets out of k8s.

Copy link
Collaborator

@xperimental xperimental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea overall and seems to work just as before 👍

Only have a few minor comments. In general I noticed a few comments that we had before because most functions were public, which are not necessary anymore (because they do not document any special behaviour).

operator/internal/handlers/internal/gateway/gateway.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/gateway/gateway.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/gateway/modes.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/gateway/modes.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/rules/rules.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/rules/rules.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/rules/rules.go Outdated Show resolved Hide resolved
operator/internal/handlers/internal/storage/storage.go Outdated Show resolved Hide resolved
}

// extractSecret reads a k8s secret into a manifest object storage struct if valid.
func extractSecret(s *corev1.Secret, secretType lokiv1.ObjectStorageSecretType) (storage.Options, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we stick to the pointered return type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because when we pass back to the manifests.Options we use a non-pointered version.

@periklis periklis enabled auto-merge (squash) January 12, 2024 19:12
@periklis periklis merged commit 0065fd6 into grafana:main Jan 12, 2024
14 checks passed
periklis added a commit to periklis/loki that referenced this pull request Jan 12, 2024
periklis added a commit to periklis/loki that referenced this pull request Jan 12, 2024
periklis added a commit to periklis/loki that referenced this pull request Jan 12, 2024
periklis added a commit to periklis/loki that referenced this pull request Jan 12, 2024
periklis added a commit to periklis/loki that referenced this pull request Jan 18, 2024
periklis added a commit to periklis/loki that referenced this pull request Jan 18, 2024
periklis added a commit to periklis/loki that referenced this pull request Jan 18, 2024
openshift-merge-bot bot added a commit to openshift/loki that referenced this pull request Jan 18, 2024
openshift-merge-bot bot added a commit to openshift/loki that referenced this pull request Jan 18, 2024
openshift-merge-bot bot added a commit to openshift/loki that referenced this pull request Jan 18, 2024
rhnasc pushed a commit to inloco/loki that referenced this pull request Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants