Skip to content

Conversation

@enrichman
Copy link
Collaborator

@enrichman enrichman commented Oct 23, 2025

Moving customCAs field to be a pointer. This will avoid creating an empty struct by default, when not needed:

apiVersion: k3k.io/v1alpha1
kind: Cluster
metadata:
  name: foo
  namespace: k3k-foo
spec:
  customCAs:
    sources:
      clientCA: {}
      etcdPeerCA: {}
      etcdServerCA: {}
      requestHeaderCA: {}
      serverCA: {}
      serviceAccountToken: {}

Also moving the enabled to true as default, and the secretName as a required field.

This will result in not having the customCAs if not provided, and force the user providing the secretName.

This way the validateCustomCACerts check should not be needed, but...

Result:

apiVersion: k3k.io/v1alpha1
kind: Cluster
metadata:
  name: foo
  namespace: k3k-foo
spec:
  customCAs:
    enabled: true
    sources:
      clientCA:
        secretName: foo
      etcdPeerCA:
        secretName: foo
      etcdServerCA:
        secretName: foo
      requestHeaderCA:
        secretName: foo
      serverCA:
        secretName: foo
      serviceAccountToken:
        secretName: foo

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2025

Codecov Report

❌ Patch coverage is 45.45455% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.43%. Comparing base (ee7eac8) to head (8209a01).

Files with missing lines Patch % Lines
pkg/controller/cluster/cluster.go 0.00% 2 Missing and 1 partial ⚠️
pkg/controller/cluster/server/server.go 33.33% 1 Missing and 1 partial ⚠️
cli/cmds/cluster_create.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #527      +/-   ##
==========================================
+ Coverage   58.63%   59.43%   +0.79%     
==========================================
  Files          56       56              
  Lines        6634     5132    -1502     
==========================================
- Hits         3890     3050     -840     
+ Misses       2472     1805     -667     
- Partials      272      277       +5     
Flag Coverage Δ
cli 53.07% <0.00%> (+1.14%) ⬆️
controller 58.13% <45.45%> (+1.43%) ⬆️
e2e 58.13% <45.45%> (+1.43%) ⬆️
unit 41.70% <0.00%> (+0.97%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@pmatseykanets pmatseykanets left a comment

Choose a reason for hiding this comment

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

Overall looks reasonable.

Comment on lines +437 to +439
if s.cluster.Spec.CustomCAs == nil {
return nil, nil, fmt.Errorf("customCAs not found")
}

Choose a reason for hiding this comment

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

Seems to be unnecessary given the conditional on L333.

Copy link
Collaborator Author

@enrichman enrichman Oct 23, 2025

Choose a reason for hiding this comment

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

Yes, that's true. I just wanted to be extra safe in case someone calls this method and forgets to check that. :)

@enrichman enrichman merged commit 075d72d into rancher:main Oct 23, 2025
8 checks passed
@enrichman enrichman deleted the cleanup-customCAs branch October 23, 2025 20:11
var (
volumes []v1.Volume
mounts []v1.VolumeMount
sortedCertIDs = sortedKeys(caCertMap)

Choose a reason for hiding this comment

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

This can be

Suggested change
sortedCertIDs = slices.Sorted(maps.Keys(caCertMap))

Choose a reason for hiding this comment

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

On a different note is there any reason why it should be sorted? If yes is there any reason not to pre-sort it as it's hardcoded?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants