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

CFE-1132: EFS Access Point Tags Update DAY2 #313

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/openshift/library-go v0.0.0-20241120135057-fc703a7407c9
github.com/prometheus/client_golang v1.20.5
github.com/spf13/cobra v1.8.1
golang.org/x/time v0.8.0
gopkg.in/ini.v1 v1.67.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.31.3
Expand Down Expand Up @@ -112,7 +113,6 @@ require (
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
google.golang.org/genproto v0.0.0-20240709173604-40e1e62336c5 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240711142825-46eb208f015d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240711142825-46eb208f015d // indirect
Expand Down
56 changes: 55 additions & 1 deletion pkg/driver/aws-efs/aws_efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"

opv1 "github.com/openshift/api/operator/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down Expand Up @@ -102,10 +103,16 @@ func GetAWSEFSOperatorConfig() *config.OperatorConfig {
// after a client connection + cluster flavour are established.
func GetAWSEFSOperatorControllerConfig(ctx context.Context, flavour generator.ClusterFlavour, c *clients.Clients) (*config.OperatorControllerConfig, error) {
cfg := operator.NewDefaultOperatorControllerConfig(flavour, c, "AWSEFS")
cfg.AddDeploymentHookBuilders(c, withCABundleDeploymentHook, withFIPSDeploymentHook)
cfg.AddDeploymentHookBuilders(c, withCABundleDeploymentHook, withFIPSDeploymentHook, withCustomTags)
cfg.DeploymentWatchedSecretNames = append(cfg.DeploymentWatchedSecretNames, cloudCredSecretName, metricsCertSecretName)
cfg.AddDaemonSetHookBuilders(c, withFIPSDaemonSetHook, withVolumeMetricsDaemonSetHook)
cfg.AddCredentialsRequestHook(stsCredentialsRequestHook)
if flavour == generator.FlavourHyperShift {
accessPointsTagController := NewEFSAccessPointTagsController(cfg.GetControllerName("EFSAccessPointTagsController"), c, c.EventRecorder)
cfg.ExtraControlPlaneControllers = append(cfg.ExtraControlPlaneControllers, accessPointsTagController)
cfg.DeploymentInformers = append(cfg.DeploymentInformers, c.KubeInformers.InformersFor("").Core().V1().PersistentVolumes().Informer())
cfg.DeploymentInformers = append(cfg.DeploymentInformers, c.KubeInformers.InformersFor(awsEFSSecretNamespace).Core().V1().Secrets().Informer())
}

return cfg, nil
}
Expand Down Expand Up @@ -235,3 +242,50 @@ func withVolumeMetricsDaemonSetHook(c *clients.Clients) (csidrivernodeservicecon
return hook, informers

}

// withCustomTags add tags from Infrastructure.Status.PlatformStatus.AWS.ResourceTags to the driver command line as
// --tags=<key1>:<value1> <key2>:<value2>,...
func withCustomTags(c *clients.Clients) (dc.DeploymentHookFunc, []factory.Informer) {
hook := func(spec *opv1.OperatorSpec, deployment *appsv1.Deployment) error {
infraLister := c.GetInfraInformer().Lister()
infra, err := infraLister.Get(infrastructureName)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I would move this code to a different function and perform this computation only if container in question is csi-driver

return err
}
if infra.Status.PlatformStatus == nil || infra.Status.PlatformStatus.AWS == nil {
return nil
}

userTags := infra.Status.PlatformStatus.AWS.ResourceTags
if len(userTags) == 0 {
return nil
}

// Create a slice of formatted key:value pairs
tagPairs := make([]string, 0, len(userTags))
for _, userTag := range userTags {
// Skip tags with empty keys or values to avoid invalid formatting
if userTag.Key == "" || userTag.Value == "" {
continue
}
tagPairs = append(tagPairs, fmt.Sprintf("%s:%s", userTag.Key, userTag.Value))
}

// Join the tag pairs with a space separator
tags := strings.Join(tagPairs, " ")
tagsArgument := fmt.Sprintf("--tags=%s", tags)

for i := range deployment.Spec.Template.Spec.Containers {
container := &deployment.Spec.Template.Spec.Containers[i]
if container.Name != "csi-driver" {
continue
}
container.Args = append(container.Args, tagsArgument)
}
return nil
}
informers := []factory.Informer{
c.GetInfraInformer().Informer(),
}
return hook, informers
}
Loading