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

[FE]: Default excludedFields ConfigMaps #47

Open
damsien opened this issue Dec 23, 2024 · 0 comments
Open

[FE]: Default excludedFields ConfigMaps #47

damsien opened this issue Dec 23, 2024 · 0 comments
Assignees
Labels
feature A feature that is listed in the roadmap

Comments

@damsien
Copy link
Collaborator

damsien commented Dec 23, 2024

Roadmap 2025/01 Default excludedFields ConfigMaps.
As the Platform Engineer of my team, I want to set defaults excludedFields ConfigMaps that will be applied for all of the RemoteSyncers of the cluster.

What to do

1. Check for the env var

In the convertToYaml() function, add some lines that check for all configmaps in the namespace where Syngit is installed (os.Getenv("MANAGER_NAMESPACE")) which has the syngit.io/cluster-default-excluded-fields: "true" label (using wrc.k8sClient).

2. Move the excludedFields remover block into a function

Move the following block into a function because it will be used twice. 1. For the remoteSyncer.Spec.ExcludedFieldsConfigMapRef (is specified) & 2. For the default excluded fields (if some exist).

ctx := context.Background()
secretNamespacedName := &types.NamespacedName{
Namespace: wrc.remoteSyncer.Namespace,
Name: wrc.remoteSyncer.Spec.ExcludedFieldsConfigMapRef.Name,
}
excludedFieldsConfig := &corev1.ConfigMap{}
err := wrc.k8sClient.Get(ctx, *secretNamespacedName, excludedFieldsConfig)
if err != nil {
errMsg := err.Error()
details.messageAddition = errMsg
return errors.New(errMsg)
}
yamlString := excludedFieldsConfig.Data["excludedFields"]
var excludedFields []string
// Unmarshal the YAML string into the Go array
err = yaml.Unmarshal([]byte(yamlString), &excludedFields)
if err != nil {
errMsg := "failed to convert the excludedFields from the ConfigMap (wrong yaml format)"
details.messageAddition = errMsg
return errors.New(errMsg)
}

The function signature:

func (wrc *WebhookRequestChecker) getPathsFromConfigMap(remoteSyncer syngit.RemoteSyncer) paths []string {}

The function call:

paths = append(paths, wrc.getPathsFromConfigMap(wrc.remoteSyncer)...)

In the function, search for the key excludedFields in the ConfigMap..

3. Check for the excluded fields

For each ConfigMaps (with the correct label) retrieved, call the function.

4. Update the chart

Go to the latest chart version https://github.com/syngit-org/syngit/tree/main/charts. Create a config folder and create the ConfigMap.

{{- if eq .config.webhook.defaultExcludedFields.enabled true }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: basic-excluded-fields
  namespace: {{ .Release.Namespace }}
  labels:
    syngit.io/cluster-default-excluded-fields: "true"
data:
  excludedFields: |
    - metadata.annotations.[kubectl.kubernetes.io/last-applied-configuration]
    - metadata.creationTimestamp
    - metadata.generateName
    - metadata.generation
    - metadata.managedFields
    - metadata.resourceVersion
    - metadata.uid
    - status
{{- end }}

Add a .config.defaultExcludedFields.enabled: true to the values.yaml.

Additional context

If you have any questions, please tag @damsien.

@damsien damsien added enhancement Request for enhancement good first issue Good for newcomers feature A feature that is listed in the roadmap and removed enhancement Request for enhancement good first issue Good for newcomers labels Dec 23, 2024
@damsien damsien changed the title [FE]: Default excludedFields option passed as env var to the controller [FE]: Default excludedFields ConfigMaps Jan 2, 2025
@damsien damsien self-assigned this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A feature that is listed in the roadmap
Projects
None yet
Development

No branches or pull requests

1 participant