Jira (PUP-11201) Refine when the last used environment is used

49 views
Skip to first unread message

Josh Cooper (Jira)

unread,
Aug 5, 2021, 8:05:02 PM8/5/21
to puppe...@googlegroups.com
Josh Cooper created an issue
 
Puppet / Bug PUP-11201
Refine when the last used environment is used
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2021/08/05 5:04 PM
Priority: Normal Normal
Reporter: Josh Cooper

With the recent changes in PUP-10216, the agent stores the last used environment in last_run_summary.yaml. If the next run does not specify an environment on the CLI, then the last used environment always takes precedence over the environment specified in puppet.conf. For example, given:

# puppet agent -t --environment feature_branch
# puppet agent -t

If the agent is allowed to specify its environment:

Prior to PUP-10216, the second run would use the original configured environment from puppet.conf or default to "production".

After PUP-10216, the second run uses the "feature_branch" environment. This is also true if the second run occurs in the background (systemd/cron), which is especially surprising.

In cases where the agent is not allowed to specify its environment, the last used environment provides the same function that the node request did. So the agent's behavior before and after PUP-10216 is the same, assuming the agent pluginsync'ed the right set of facts and classification doesn't change between runs.

This ticket proposes we make an exception for the agent-specified case so that the second run only uses the environment from the previous run if it was server-specified. Otherwise, the agent should start in its configured environment (from puppet.conf) or default to "production".

So I think this means:

  1. If environment specified on CLI, use it
  2. If last environment was server-specified, use it
  3. Otherwise use our configured environment Puppet[:environment]

I think we can detect if the last environment was server-specified by saving both the initial environment and the converged environment. If those are different, then the server told us to use a different environment.

If they are the same, then it doesn't matter if it's agent or server-specified, just use it.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Josh Cooper (Jira)

unread,
Aug 5, 2021, 8:07:03 PM8/5/21
to puppe...@googlegroups.com
Josh Cooper updated an issue
Change By: Josh Cooper
Release Notes: Not Needed
Release Notes Summary: This issue was introduced during development and never released.

Ciprian Badescu (Jira)

unread,
Aug 6, 2021, 4:35:04 PM8/6/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
With the recent changes in PUP-10216, the agent stores the last used environment in {{last_run_summary.yaml}}. If the next run does not specify an environment on the CLI, then the last used environment *always* takes precedence over the environment specified in puppet.conf. For example, given:
{noformat}# puppet agent -t --environment feature_branch
# puppet agent -t
{noformat}

If the agent is allowed to specify its environment:

Prior to PUP-10216, the second run would use the original configured environment from puppet.conf or default to "production".

After PUP-10216, the second run uses the "feature_branch" environment. This is also true if the second run occurs in the background (systemd/cron), which is especially surprising.

In cases where the agent is *not* allowed to specify its environment, the last used environment provides the same function that the node request did. So the agent's behavior before and after PUP-10216 is the same, assuming the agent pluginsync'ed the right set of facts and classification doesn't change between runs.


This ticket proposes we make an exception for the agent-specified case so that the second run only uses the environment from the previous run if it was server-specified. Otherwise, the agent should start in its configured environment (from puppet.conf) or default to "production".

So I think this means:

# If environment specified on CLI, use it
# If last environment was server-specified, use it
# Otherwise use our configured environment {{Puppet[:environment]}}

I think we can detect if the last environment was server-specified by saving both the initial environment and the converged environment
in {{last_run_summary . yaml}}. If those are different, then the server told us to use a different environment.


If they are the same, then it doesn't matter if it's agent or server-specified, just use it.

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:17:02 AM8/9/21
to puppe...@googlegroups.com
  1. If environment specified on CLI, use it
  1. If environment specified on puppet.conf, use it
  1. If last environment was server-specified, use it
  1. Otherwise use our default (production)

This should be fixed since it will be different behavior than before, when we used to do the node request.

 

 

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:27:02 AM8/9/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
With the recent changes in PUP-10216, the agent stores the last used environment in {{last_run_summary.yaml}}. If the next run does not specify an environment on the CLI, then the last used environment *always* takes precedence over the environment specified in puppet.conf. For example, given:
{noformat}# puppet agent -t --environment feature_branch
# puppet agent -t
{noformat}
If the agent is allowed to specify its environment:

Prior to PUP-10216, the second run would use the original configured environment from puppet.conf or default to "production".

After PUP-10216, the second run uses the "feature_branch" environment. This is also true if the second run occurs in the background (systemd/cron), which is especially surprising.

In cases where the agent is *not* allowed to specify its environment, the last used environment provides the same function that the node request did. So the agent's behavior before and after PUP-10216 is the same, assuming the agent pluginsync'ed the right set of facts and classification doesn't change between runs.

This ticket proposes we make an exception for the agent-specified case so that the second run only uses the environment from the previous run if it was server-specified. Otherwise, the agent should start in its configured environment (from puppet.conf) or default to "production".

So I think this means:
# If environment specified on CLI, use it
# If last environment was server-specified, use it
# Otherwise use our configured environment {{Puppet[:environment]}}

I think we can detect if the last environment was server-specified by saving both the initial environment and the converged environment in {{last_run_summary.yaml}}. If those are different, then the server told us to use a different environment.

If they are the same, then it doesn't matter if it's agent or server-specified, just use
it. Puppet[:environment]

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:31:01 AM8/9/21
to puppe...@googlegroups.com
If they are the same, then it doesn't matter if it's agent or server-specified, just use Puppet[:environment]

Initial should be initially set with the values from first run (step 1 or 3) and carried over, not overwritten with values received from server

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:44:01 AM8/9/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:44:04 AM8/9/21
to puppe...@googlegroups.com

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:51:02 AM8/9/21
to puppe...@googlegroups.com

Gabriel Nagy (Jira)

unread,
Aug 9, 2021, 5:41:04 AM8/9/21
to puppe...@googlegroups.com
Gabriel Nagy assigned an issue to Gabriel Nagy
Change By: Gabriel Nagy
Assignee: Gabriel Nagy

Gabriel Nagy (Jira)

unread,
Aug 9, 2021, 5:54:04 AM8/9/21
to puppe...@googlegroups.com
Gabriel Nagy commented on Bug PUP-11201
 
Re: Refine when the last used environment is used

Previous behavior (before we removed the node request) was to skip the node request if a cached catalog/catalog is given, or if strict_environment_mode is true. So the node request was always performed regardless of the CLI/config value for environment

Gabriel Nagy (Jira)

unread,
Aug 9, 2021, 11:19:03 AM8/9/21
to puppe...@googlegroups.com

Molly Waggett (Jira)

unread,
Aug 9, 2021, 2:28:03 PM8/9/21
to puppe...@googlegroups.com

What is the expected behavior if a specified environment is not found? Previously, running puppet agent -t --environment test would error if the 'test' environment didn't exist. Now it falls back to a good environment ('production' in my case, but not sure if that's coming from the last-used env or just defaults to 'production' or something else). Is that the new desired behavior?

Gabriel Nagy (Jira)

unread,
Aug 9, 2021, 2:54:04 PM8/9/21
to puppe...@googlegroups.com
Gabriel Nagy commented on Bug PUP-11201

That's the correct (new) behavior, work for that was done in https://tickets.puppetlabs.com/browse/PUP-6802

Ciprian Badescu (Jira)

unread,
Aug 9, 2021, 3:17:02 PM8/9/21
to puppe...@googlegroups.com

I think that the environment is specified in command line has always priority and the last server environment is not used in this case. I can see the following cases

  1. the server is authoritative and the environment requested by the agent is not existing: this was an issue and it was fixed in https://tickets.puppetlabs.com/browse/PUP-6802 and the environment to be used will be decided by server
  2. the agent is authoritative and the environment requested by the agent is not existing: now it will fail faster

Molly Waggett, can you detail your test case?

 

Molly Waggett (Jira)

unread,
Aug 9, 2021, 3:36:03 PM8/9/21
to puppe...@googlegroups.com

sure, the following r10k acceptance tests are currently failing:

These are testing cases where an environment has been deleted or was never managed in the first place, so puppet should not be able to run against these environments. We previously expected puppet runs to fail, but now they fall back to the 'production' environment. We can update our tests if need be, but I wasn't sure if this behavior was intentional or if it's a bug.

Ciprian Badescu (Jira)

unread,
Aug 10, 2021, 4:06:04 AM8/10/21
to puppe...@googlegroups.com

It looks that if the environment was deleted, the default classifier answers to the agent to use the production environment, this is what makes the agent run to continue with the production environment.

This could be confusing for people using non-existing environment and expecting puppet-run to fail even if the classifier would classify agent to different environment

 

Ciprian Badescu (Jira)

unread,
Aug 11, 2021, 5:21:03 AM8/11/21
to puppe...@googlegroups.com
Ciprian Badescu updated an issue
Change By: Ciprian Badescu
Sprint: NW-2021-08-11 , NW-2021-08-25

Gabriel Nagy (Jira)

unread,
Aug 12, 2021, 1:00:03 AM8/12/21
to puppe...@googlegroups.com

Gheorghe Popescu (Jira)

unread,
Aug 12, 2021, 4:41:03 AM8/12/21
to puppe...@googlegroups.com
Gheorghe Popescu updated an issue
 
Change By: Gheorghe Popescu
Fix Version/s: PUP 7.10.0

Dorin Pleava (Jira)

unread,
Sep 27, 2021, 8:54:02 AM9/27/21
to puppe...@googlegroups.com
Dorin Pleava updated an issue
Change By: Dorin Pleava
Fix Version/s: PUP 6.25.0
Reply all
Reply to author
Forward
0 new messages