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

[feat]: [CI-12562]: support for output secrets plugins #282

Merged
merged 13 commits into from
May 21, 2024

Conversation

Sapa96
Copy link
Contributor

@Sapa96 Sapa96 commented May 15, 2024

Requirement : https://harness.atlassian.net/wiki/x/rgFbEgU
Changes

  1. introduction of secret env file for output secrets of plugin

Testing

  1. Tested in local setup for the following scenarios

       - with old output yaml runstep 
       -  new output yaml  runstep 
       - plugin step with outputs
       - plugin step with output secrets
       - plugin step with combination of outputs and  output secrets
       - plugin step with no exports
    
Screenshot 2024-05-20 at 10 55 17 Screenshot 2024-05-20 at 10 55 25

@CLAassistant
Copy link

CLAassistant commented May 15, 2024

CLA assistant check
All committers have signed the CLA.

@Sapa96 Sapa96 force-pushed the feature/output_secrets_plugin branch from 4e18543 to 9b22760 Compare May 20, 2024 05:43
@Sapa96 Sapa96 changed the title [feat]: [CI-12562]: initial commit support for secrets [feat]: [CI-12562]: support for output secrets plugins May 20, 2024
@Sapa96 Sapa96 requested a review from vistaarjuneja May 20, 2024 07:27
Comment on lines 122 to 132
finalErr = err
for _, key := range r.OutputVars {
if _, ok := outputs[key]; ok {
output := &api.OutputV2{
Key: key,
Value: outputs[key],
Type: outputVariableTypeString,
}
outputsV2 = append(outputsV2, output)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to add this ?
OutputVars is deprecated so we can skip this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pipelines with older yaml can still use this OutputVars fields right ? added this code for backward compatibility

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but yaml field is same. Internally we parse it to the new format. You can once check with @sahithibanda01 since she implemented it. AFIAK this is not required.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but yaml field is same. Internally we parse it to the new format. You can once check with @sahithibanda01 since she implemented it. AFIAK this is not required.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove this elseif cond altogether

pipeline/runtime/run.go Show resolved Hide resolved
pipeline/runtime/runtest.go Outdated Show resolved Hide resolved
@@ -106,6 +106,9 @@ func executeRunTestsV2Step(ctx context.Context, f RunFunc, r *api.StartStepReque
outputFile := fmt.Sprintf("%s/%s-output.env", pipeline.SharedVolPath, step.ID)
step.Envs["DRONE_OUTPUT"] = outputFile

outputSecretsFile := fmt.Sprintf("%s/%s-output-secrets.env", pipeline.SharedVolPath, step.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

observed the following support in the file . so added logic for secrets here also . can be removed if not required
step.Envs["DRONE_OUTPUT"] = outputFile

Copy link
Contributor

Choose a reason for hiding this comment

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

I think let's do for run.go for now only ? If the requirement comes for runtest we can add that later ?

Comment on lines 122 to 132
finalErr = err
for _, key := range r.OutputVars {
if _, ok := outputs[key]; ok {
output := &api.OutputV2{
Key: key,
Value: outputs[key],
Type: outputVariableTypeString,
}
outputsV2 = append(outputsV2, output)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but yaml field is same. Internally we parse it to the new format. You can once check with @sahithibanda01 since she implemented it. AFIAK this is not required.

Comment on lines 122 to 132
finalErr = err
for _, key := range r.OutputVars {
if _, ok := outputs[key]; ok {
output := &api.OutputV2{
Key: key,
Value: outputs[key],
Type: outputVariableTypeString,
}
outputsV2 = append(outputsV2, output)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but yaml field is same. Internally we parse it to the new format. You can once check with @sahithibanda01 since she implemented it. AFIAK this is not required.

Comment on lines 122 to 132
finalErr = err
for _, key := range r.OutputVars {
if _, ok := outputs[key]; ok {
output := &api.OutputV2{
Key: key,
Value: outputs[key],
Type: outputVariableTypeString,
}
outputsV2 = append(outputsV2, output)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove this elseif cond altogether

@@ -106,6 +106,9 @@ func executeRunTestsV2Step(ctx context.Context, f RunFunc, r *api.StartStepReque
outputFile := fmt.Sprintf("%s/%s-output.env", pipeline.SharedVolPath, step.ID)
step.Envs["DRONE_OUTPUT"] = outputFile

outputSecretsFile := fmt.Sprintf("%s/%s-output-secrets.env", pipeline.SharedVolPath, step.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think let's do for run.go for now only ? If the requirement comes for runtest we can add that later ?

@@ -66,6 +67,9 @@ func executeRunStep(ctx context.Context, f RunFunc, r *api.StartStepRequest, out
}
}

outputSecretsFile := fmt.Sprintf("%s/%s-output-secrets.env", pipeline.SharedVolPath, step.ID)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add the same condition as L52 and add a SecretVarFile variable. If it's set, we will use that directly otherwise generate it similarly to what you have. This will help integrate with runner in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

if r.SecretVarFile != "" {
     // set the env variable to r.SecretVarFile
}

return exited, outputs, exportEnvs, artifact, nil, string(optimizationState), nil

//checking exported secrets from plugins if any
_, secretErr := os.Stat(outputSecretsFile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's log if secretErr != nil

Copy link
Contributor Author

@Sapa96 Sapa96 May 20, 2024

Choose a reason for hiding this comment

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

@vistaarjuneja
Why do we need to log it ? this will return err for all the existing plugins and run steps also as they dont use secret file as of now . this check is to understand whether a secret is exported or not .
if we log it , the error will be logged for all the existing run steps and plugin steps .

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack, let's change it to this in a single line:

if _, err := os.Stat(outputSecretsFile); err == nil {
  
}

pipeline/runtime/run.go Show resolved Hide resolved
pipeline/runtime/runtest.go Outdated Show resolved Hide resolved
pipeline/runtime/common.go Outdated Show resolved Hide resolved
api/api.go Outdated
type OutputType string

const (
STRING OutputType = "STRING"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's renamename these so it's more clear what it does

      OutputTypeString OutputType = "STRING"
      OutputTypeSecret OutputType = "SECRET"

so api.OutputTypeString is more clear

api/api.go Show resolved Hide resolved
return exited, outputs, exportEnvs, artifact, nil, string(optimizationState), nil

//checking exported secrets from plugins if any
_, secretErr := os.Stat(outputSecretsFile)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ack, let's change it to this in a single line:

if _, err := os.Stat(outputSecretsFile); err == nil {
  
}

pipeline/runtime/run.go Outdated Show resolved Hide resolved
@Sapa96 Sapa96 merged commit c6b9be5 into main May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants