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

chore: support inject envFrom by secret #8115

Merged
merged 5 commits into from
Sep 13, 2024

Conversation

sophon-zt
Copy link
Contributor

There are two issues left to be dealt with in this sshd related PR:

  1. It is not safe to store sshd key in configmap;
  2. sshd key is exported as env, and scripts are required to handle these environment variables;

This pr can mount the sshd key to the container's volume as a secret.
refer to sshd demo: https://github.com/apecloud/kubeblocks-addons/pull/1017/files

@sophon-zt sophon-zt requested a review from a team as a code owner September 10, 2024 02:46
@github-actions github-actions bot added the size/L Denotes a PR that changes 100-499 lines. label Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 60.17699% with 45 lines in your changes missing coverage. Please review.

Project coverage is 63.24%. Comparing base (4f74673) to head (726ea6d).
Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controller/configuration/envfrom_utils.go 62.66% 25 Missing and 3 partials ⚠️
pkg/controller/configuration/template_wrapper.go 61.53% 2 Missing and 3 partials ⚠️
pkg/controller/configuration/pipeline.go 20.00% 2 Missing and 2 partials ⚠️
controllers/apps/configuration/reconcile_task.go 75.00% 2 Missing and 1 partial ⚠️
pkg/controller/configuration/config_utils.go 25.00% 2 Missing and 1 partial ⚠️
apis/apps/v1alpha1/config_meta.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8115      +/-   ##
==========================================
+ Coverage   62.49%   63.24%   +0.74%     
==========================================
  Files         333      333              
  Lines       40569    41228     +659     
==========================================
+ Hits        25354    26074     +720     
+ Misses      12946    12883      -63     
- Partials     2269     2271       +2     
Flag Coverage Δ
unittests 63.24% <60.17%> (+0.74%) ⬆️

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.

@@ -41,8 +41,11 @@ import (
viper "github.com/apecloud/kubeblocks/pkg/viperx"
)

func createConfigObjects(cli client.Client, ctx context.Context, objs []client.Object) error {
func createConfigObjects(cli client.Client, ctx context.Context, objs []client.Object, secretObjs []client.Object) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

secretObjs => excludeObjs

@@ -366,10 +366,13 @@ func (p *updatePipeline) UpdateConfigVersion(revision string) *updatePipeline {
func (p *updatePipeline) Sync() *updatePipeline {
return p.Wrap(func() error {
if p.ConfigConstraintObj != nil && !p.isDone() {
if err := SyncEnvConfigmap(*p.configSpec, p.newCM, &p.ConfigConstraintObj.Spec, p.Client, p.Context); err != nil {
if err := SyncEnvConfigmap(*p.configSpec, p.newCM, &p.ConfigConstraintObj.Spec, p.Client, p.Context, p.ctx.Cluster, p.ctx.SynthesizedComponent); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

SyncEnvConfigmap() is handling the ConfigMap resource, so should a new function (like SyncEnvSecret()) be added for the Secret resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AsSecret is only applicable to configuration templates that allow injectEnvTo. AsSecret is not supported for non-envFrom configuration templates. The reason is that the related modifications are too large. This may be used to support it in future.

For the configuration template of injectEnvTo, the rendered configmap/secret won't be used, so the configmap/secret of InjectEnvTo does not need to be created. Here ignore the secret for compatibility considerations, the previous ComponentTemplateSpec.VolumeName is a required field, addon may mount the volume to the container, and removing it directly may cause problems.

return err
}
}
if p.configSpec.InjectEnvEnabled() && p.configSpec.ToSecret() {
return nil
}
switch {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should add a case for the secret resource?

@apecloud-bot apecloud-bot added the approved PR Approved Test label Sep 12, 2024
@apecloud-bot apecloud-bot removed the approved PR Approved Test label Sep 13, 2024
@sophon-zt
Copy link
Contributor Author

/approve for test

@apecloud-bot apecloud-bot added the approved PR Approved Test label Sep 13, 2024
@sophon-zt sophon-zt merged commit 9b8eef3 into main Sep 13, 2024
36 checks passed
@sophon-zt sophon-zt deleted the support/support-generate-secret-for-config-template branch September 13, 2024 06:41
@github-actions github-actions bot added this to the Release 0.9.2 milestone Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved PR Approved Test size/L Denotes a PR that changes 100-499 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants