-
Notifications
You must be signed in to change notification settings - Fork 55
Enable re-discovery of resources during deployment #1366
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
Enable re-discovery of resources during deployment #1366
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new resourceDiscovery metadata option under the Microsoft.DSC namespace to support discovering resources during deployment, enabling scenarios where configurations install resources that are then used later in the same run.
Changes:
- Introduces a new
ResourceDiscoveryMode(preDeployment/duringDeployment) metadata option and wires it into configuration validation and the discovery pipeline, including dynamic re-discovery viaDiscovery.refresh_cacheandCommandDiscovery’s discovery mode. - Adds a new test-only resource
Test/CopyResource(implemented via thedsctesttool) that can copy an existing resource manifest and retarget itstype, plus a manifest entry and schema support for this resource. - Extends PowerShell tests to cover the new
resourceDiscoverybehavior, verifying both failure in pre-deployment mode and success when discovery happens during deployment.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tools/dsctest/src/main.rs |
Wires a new copy-resource subcommand into dsctest, handling JSON input, invoking the copy helper, and exposing a schema for the new CopyResource input. |
tools/dsctest/src/copy_resource.rs |
Defines the CopyResource schema and implements copy_the_resource, which rewrites the type in a source manifest and emits a new .dsc.resource.json file for the desired type. |
tools/dsctest/src/args.rs |
Adds CopyResource to the Schemas enum and defines the copy-resource CLI subcommand used by the test resource manifest. |
tools/dsctest/dsctest.dsc.manifests.json |
Registers Test/CopyResource as a test resource backed by the dsctest binary, including schema wiring via the schema subcommand. |
lib/dsc-lib/src/discovery/mod.rs |
Extends the Discovery struct with a refresh_cache flag and updates find_resource/find_resources to support forced rediscovery using the new discovery mode. |
lib/dsc-lib/src/discovery/discovery_trait.rs |
Updates the ResourceDiscovery trait to be aware of ResourceDiscoveryMode and adds a set_discovery_mode method implemented by discovery backends. |
lib/dsc-lib/src/discovery/command_discovery.rs |
Tracks a discovery_mode in CommandDiscovery and adjusts its caching and discovery behavior so that DuringDeployment forces re-discovery while allowing pre-deployment caching when appropriate. |
lib/dsc-lib/src/configure/mod.rs |
Reads the new metadata.Microsoft.DSC.resourceDiscovery value, skips pre-deployment resource validation when set to duringDeployment, and sets Discovery.refresh_cache for runtime rediscovery. |
lib/dsc-lib/src/configure/config_doc.rs |
Defines the ResourceDiscoveryMode enum, adds it to MicrosoftDscMetadata, and updates serde metadata so resourceDiscovery is available in the config schema under the Microsoft.DSC namespace. |
lib/dsc-lib/locales/en-us.toml |
Adds a localized message indicating that resource discovery is being skipped due to resourceDiscovery: duringDeployment. |
dsc/tests/dsc_discovery.tests.ps1 |
Adds Pester tests covering resourceDiscovery modes, including a scenario that uses Test/CopyResource to install a resource during deployment and then invoke it in the same configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
PR Summary
To support the scenario where the config installs resources that will get used later, this change introduces new metadata under the
Microsoft.DSCnamespace to enable re-discovery of resources during deployment:The new
resourceDiscoveryproperty acceptspreDeployment(the default) orduringDeployment.preDeploymentmeans that all resources (except within a group) are discovered and validated before deployment. So if any resource is missing, no resources are executed (this PR fixes that regression).For testing, this PR creates a new test resource where you can specify a manifest file to copy and rename the type name to simulate the installation of a new resource (the new resource still needs to adhere to current discovery rules).
One side effect here is that to support dynamically installed resources, before EVERY resource invocation, a discovery is performed. We can optimize this in the future later based on other ideas in the issue below.
This change required storing the mode in Discovery and also CommandDiscovery to force rediscovery since both previously optimized where if it had results cached, it skipped discovery every time.
Also fixed an issue in the
Install-Protobufhelper function aswingetreturns a non-zero exit code if the package is already installed. Fix is to use--forceto force an install.PR Context
Fix #1170