Skip to content

Conversation

Yadavanurag13
Copy link
Contributor

Description

This PR adds two new flags to the score-k8s generate command to support namespace management in generated Kubernetes manifests:

  1. --namespace: Sets the namespace for all generated resources
  2. --generate-namespace: Creates a namespace manifest (requires --namespace to be set)

The implementation includes:

  • Validation to ensure --generate-namespace is only used with --namespace
  • Automatic namespace injection into all resource manifests when --namespace is used
  • Generation of a properly labeled namespace manifest when --generate-namespace is used
  • Comprehensive test coverage for all new functionality
  • Updated command examples and documentation

What does this PR do?

This PR implements the feature request from issue #172 to add namespace management capabilities to the score-k8s generate command. It provides users with the ability to:

  • Set a namespace for all generated resources without manual patching
  • Automatically generate a namespace manifest with proper labels

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • New chore (expected functionality to be implemented)

Checklist:

  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I've signed off with an email address that matches the commit author.

@Yadavanurag13
Copy link
Contributor Author

Hii @mathieu-benoit. I have made changes for the requested feature. I have added the test also and tested it locally. Could you please review the changes.

If any modification required please let me know.

@7h3-3mp7y-m4n
Copy link
Contributor

Hey @Yadavanurag13, thank you for your PR, it looks wonderful! 🙌
I'm not a maintainer, but I’ve suggested a few changes that might be helpful. Let me know what you think!
In the meantime, please hold off on making any changes based on my review until a maintainer has had a chance to take a look. I’ll ping them for you. :)

Copy link
Contributor

@mathieu-benoit mathieu-benoit left a comment

Choose a reason for hiding this comment

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

This is really great, @Yadavanurag13, super neat, thanks!

Please go through the comments and suggestions from @7h3-3mp7y-m4n (thanks!), nothing critical, but small improvements needed.

Once taken into account, could you please add a new comment in this PR with the outputs of these 3 following commands to help for the final review?

  • score-k8s generate score.yaml --namespace=test-ns --generate-namespace
  • score-k8s generate score.yaml --namespace=test-ns
  • score-k8s generate score.yaml --generate-namespace

Thanks again!

@Yadavanurag13
Copy link
Contributor Author

Thanks @7h3-3mp7y-m4n @mathieu-benoit for the review. I'll incorporate all the required changes and let u know.

Signed-off-by: Anurag Yadav <yadavanurag1310@gmail.com>
Signed-off-by: Anurag Yadav <yadavanurag1310@gmail.com>
Signed-off-by: Anurag Yadav <yadavanurag1310@gmail.com>
Signed-off-by: Anurag Yadav <yadavanurag1310@gmail.com>
@mathieu-benoit mathieu-benoit changed the title Feat: Add --namespace and --generate-namespace flags for score-k8s generate Feat: Add --namespace and --generate-namespace flags for score-k8s generate Jun 7, 2025
@mathieu-benoit mathieu-benoit self-requested a review June 9, 2025 16:50
Copy link
Contributor

@mathieu-benoit mathieu-benoit left a comment

Choose a reason for hiding this comment

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

LGTM, great job here! Thanks, @Yadavanurag13!

I just did some tests with the associated binary, see below.

./score-k8s init

If doing ./score-k8s generate score.yaml, no Namespace manifests and no namespace field in the generated Deployment and Service manifests.

If doing ./score-k8s generate score.yaml --namespace=test-ns --generate-namespace, getting:

---
apiVersion: v1
kind: Namespace
metadata:
    labels:
        app.kubernetes.io/managed-by: score-k8s
    name: test-ns
---
apiVersion: v1
kind: Service
metadata:
...
    name: example
    namespace: test-ns
...
---
apiVersion: apps/v1
kind: Deployment
metadata:
...
    name: example
    namespace: test-ns

If doing ./score-k8s generate score.yaml --namespace=test-ns, getting:

---
apiVersion: v1
kind: Service
metadata:
...
    name: example
    namespace: test-ns
...
---
apiVersion: apps/v1
kind: Deployment
metadata:
...
    name: example
    namespace: test-ns

If doing ./score-k8s generate score.yaml --generate-namespace, getting:

Error: --namespace flag is required when using --generate-namespace

If doing ./score-k8s generate --help, getting:

The generate command will convert Score files in the current Score state into a combined set of Kubernetes
manifests. All resources and links between Workloads will be resolved and provisioned as required.

"score-k8s init" MUST be run first. An error will be thrown if the project directory is not present.

Usage:
  score-k8s generate [flags]

Examples:

  # Specify Score files
  score-k8s generate score.yaml *.score.yaml

  # Regenerate without adding new score files
  score-k8s generate

  # Provide a default container image for any containers with image=.
  score-k8s generate score.yaml --image=nginx:latest

  # Provide overrides when one score file is provided
  score-k8s generate score.yaml --override-file=./overrides.score.yaml --override-property=metadata.key=value

  # Patch resulting manifests
  score-k8s generate score.yaml --patch-manifests */*/metadata.annotations.key=value --patch-manifests Deployment/foo/spec.replicas=4

  # Set namespace for all resources
  score-k8s generate score.yaml --namespace=test-ns

  # Generate namespace manifest and set namespace for all resources
  score-k8s generate score.yaml --namespace=test-ns --generate-namespace

Flags:
      --generate-namespace              If true, generate a namespace manifest. Requires --namespace to be set
  -h, --help                            help for generate
      --image string                    An optional container image to use for any container with image == '.'
      --namespace string                An optional namespace to set for all generated resources
  -o, --output string                   The output manifests file to write the manifests to (default "manifests.yaml")
      --override-property stringArray   An optional set of path=key overrides to set or remove
      --overrides-file string           An optional file of Score overrides to merge in
      --patch-manifests stringArray     An optional set of <kind|*>/<name|*>/path=key operations for the output manifests

Global Flags:
      --quiet           Mute any logging output
  -v, --verbose count   Increase log verbosity and detail by specifying this flag one or more times

All good!

@mathieu-benoit mathieu-benoit merged commit f621f71 into score-spec:main Jun 9, 2025
6 checks passed
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

Successfully merging this pull request may close these issues.

3 participants