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

Question: dynamic flux path #278

Closed
gdlx opened this issue May 7, 2024 · 5 comments
Closed

Question: dynamic flux path #278

gdlx opened this issue May 7, 2024 · 5 comments

Comments

@gdlx
Copy link

gdlx commented May 7, 2024

Hello,

I couldn’t find this information in the documentation, so I’m not sure if it’s possible: Is there a way to dynamically set a policyRef path using the cluster env or name?

Here’s the use case: We’re currently using Flux with generated YAML files stored in a Git repository. These files are organized into directories for each environment and cluster, like so: manifests/prod/my-prod-cluster/

I’d like to use Sveltos to push bootstrap manifests from the same source. However, the path would be different for each cluster. Therefore, I need to manage a ClusterProfile like this:

apiVersion: config.projectsveltos.io/v1alpha1
kind: ClusterProfile
metadata:
  name: kyverno-policies
spec:
  clusterSelector: env=prod
  policyRefs:
  - kind: GitRepository
    name: manifests
    namespace: flux-system
    path: manifests/{{ cluster.labels.env }}/{{ cluster.name }}/kyverno-policices
  dependsOn: 
  - kyverno

Another side question: Is it possible to use Sveltos without continuous sync to avoid conflict with FluxCD ? As I aim at using the same source repo, I'd like it to bootstrap new clusters but not to do any change once the cluster is ready.

Thanks !

@gianlucam76
Copy link
Member

Hi @gdlx thank you.

Regarding your second question the answer is yes. Set SyncMode to "OneTime"
In that case, when a cluster matches a ClusterProfile for the very first time, all addons and applications in the ClusterProfile will be deployed by sveltos on the cluster.

After that, any modification to ClusterProfile won't propagate to the cluster.

Regarding your first question, that is not currently possible. But I love the idea (it's very much in line with Sveltos philosophy). So I will add it. It should be easy so I can give you and image to try by end of the week.

@gianlucam76
Copy link
Member

Change was extremely easy: projectsveltos/addon-controller#533

will create a patch release v0.29.1

gianlucam76 pushed a commit to gianlucam76/addon-controller that referenced this issue May 8, 2024
For instance, this repo https://github.com/gianlucam76/kustomize
has two directories with kustomize files:

1. production
2. pre-production

The only difference between the two is that Deployment in production/helloWorld
has replicas set to 3, while the Deployment in pre-production/helloWorld has
replicase set to 1.

By creating this ClusterProfile:

```yaml
apiVersion: config.projectsveltos.io/v1alpha1
kind: ClusterProfile
metadata:
  name: flux-system
spec:
  clusterSelector: region=west
  syncMode: Continuous
  kustomizationRefs:
  - namespace: flux-system
    name: flux-system
    kind: GitRepository
    path: '{{ index .Cluster.metadata.annotations "environment" }}/helloWorld'
    targetNamespace: eng
```

For every matching cluster, Sveltos will first instantiate the __path__ so:

1. picking production/helloWorld path if cluster has annotation ```environment: production```
2. picking pre-production/helloWorld path if cluster has annotation ```environment: pre-production```

Closes [projectsveltos#532](projectsveltos#532)
Closes [278](projectsveltos/sveltos#278)
@gianlucam76
Copy link
Member

Verified with this:

  1. With flux pointing to https://github.com/gianlucam76/yaml_flux

  2. Added annotations "environment: nginx-ingress"

  3. Deployed

apiVersion: config.projectsveltos.io/v1alpha1
kind: ClusterProfile
metadata:
  name: deploy-nginx-ingress
spec:
  clusterSelector: env=fv
  policyRefs:
  - kind: GitRepository
    name: flux-system
    namespace: flux-system
    path: '{{ index .Cluster.metadata.annotations "environment" }}'

Sveltos instantiate path to "nginx-ingress" and deployed the content in that directory

@gianlucam76
Copy link
Member

@gdlx this is in v0.29.1 so closing this.

Please let me know if you encounter any issue.

Thank you

@gdlx
Copy link
Author

gdlx commented May 10, 2024

Thanks @gianlucam76, I'll try this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants