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

Avoid using twice hardcoded strings for the names of the Kube Secret keys, for AWS access/secret key vals #8345

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/apis/common/integration/v1alpha1/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ limitations under the License.

package v1alpha1

const (

// AwsAccessKey is the name of the expected key on the secret for accessing the actual AWS access key value.
AwsAccessKey = "aws.accessKey"
// AwsSecretKey is the name of the expected key on the secret for accessing the actual AWS secret key value.
AwsSecretKey = "aws.secretKey"
)

type AWSCommon struct {
// Auth is the S3 authentication (accessKey/secretKey) configuration.
Region string `json:"region,omitempty"` // AWS region
Expand Down
9 changes: 5 additions & 4 deletions pkg/reconciler/integration/sink/resources/container_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
commonv1a1 "knative.dev/eventing/pkg/apis/common/integration/v1alpha1"
"knative.dev/eventing/pkg/apis/sinks/v1alpha1"
"knative.dev/eventing/pkg/reconciler/integration"
"knative.dev/pkg/kmeta"
Expand Down Expand Up @@ -123,8 +124,8 @@ func makeEnv(sink *v1alpha1.IntegrationSink) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_S3_SINK", *sink.Spec.Aws.S3)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_ACCESSKEY", "aws.accessKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_SECRETKEY", "aws.secretKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SINK_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand All @@ -135,8 +136,8 @@ func makeEnv(sink *v1alpha1.IntegrationSink) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_SQS_SINK", *sink.Spec.Aws.SQS)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_ACCESSKEY", "aws.accessKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_SECRETKEY", "aws.secretKey", secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SINK_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand Down
18 changes: 7 additions & 11 deletions pkg/reconciler/integration/source/resources/containersource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ package resources
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
commonv1a1 "knative.dev/eventing/pkg/apis/common/integration/v1alpha1"
sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1"
"knative.dev/eventing/pkg/apis/sources/v1alpha1"
"knative.dev/eventing/pkg/reconciler/integration"
"knative.dev/pkg/kmeta"
)

const (
awsAccessKey = "aws.accessKey"
awsSecretKey = "aws.secretKey"
)

func NewContainerSource(source *v1alpha1.IntegrationSource) *sourcesv1.ContainerSource {
return &sourcesv1.ContainerSource{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -79,8 +75,8 @@ func makeEnv(source *v1alpha1.IntegrationSource) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_S3_SOURCE", *source.Spec.Aws.S3)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_ACCESSKEY", awsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_SECRETKEY", awsSecretKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_S3_SOURCE_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand All @@ -91,8 +87,8 @@ func makeEnv(source *v1alpha1.IntegrationSource) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_SQS_SOURCE", *source.Spec.Aws.SQS)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_ACCESSKEY", awsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_SECRETKEY", awsSecretKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_SQS_SOURCE_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand All @@ -103,8 +99,8 @@ func makeEnv(source *v1alpha1.IntegrationSource) []corev1.EnvVar {
envVars = append(envVars, integration.GenerateEnvVarsFromStruct("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE", *source.Spec.Aws.DDBStreams)...)
if secretName != "" {
envVars = append(envVars, []corev1.EnvVar{
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_ACCESSKEY", awsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_SECRETKEY", awsSecretKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_ACCESSKEY", commonv1a1.AwsAccessKey, secretName),
integration.MakeSecretEnvVar("CAMEL_KAMELET_AWS_DDB_STREAMS_SOURCE_SECRETKEY", commonv1a1.AwsSecretKey, secretName),
}...)
}
return envVars
Expand Down
Loading