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

custom resource: credentials_file #785

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
45 changes: 25 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ This file is used to list changes made in each version of the jenkins cookbook.

## Unreleased

- Require Chef 15.3 for custom resources unified_mode
- Require Chef 16 for resource partials
- Move credentials_file to a custom resource
- Add the credentials partial for reuse for all credentials resources

## 9.5.4 - *2022-12-08*

Standardise files with files in sous-chefs/repo-management
- Standardise files with files in sous-chefs/repo-management

## 9.5.3 - *2022-12-02*

Standardise files with files in sous-chefs/repo-management
- Standardise files with files in sous-chefs/repo-management

## 9.5.2 - *2022-03-28*

Expand Down Expand Up @@ -56,8 +61,8 @@ Standardise files with files in sous-chefs/repo-management
### Breaking Changes / Deprecations

- `jenkins_jnlp_slave`:
- Renamed `runit_groups` property to `service_groups`
- New service created -- old Runit service will need manual cleanup
- Renamed `runit_groups` property to `service_groups`
- New service created -- old Runit service will need manual cleanup

- `jenkins::_master_war`:
- New service created -- old Runit service will need manual cleanup
Expand Down Expand Up @@ -518,22 +523,22 @@ Standardise files with files in sous-chefs/repo-management
- Remove old TODO file
- Refactor attributes into semantic groupings and namespaces

- `jenkins.cli` has been removed
- `jenkins.java_home` has been changed to `jenkins.java` and accepts the full path to the java binary, not the JAVA_HOME
- `jenkins.iptables_allow` has been removed
- `jenkins.mirror` -> `jenkins.master.mirror`
- `jenkins.executor` created
- `jenkins.executor.timeout` created
- `jenkins.executor.private_key` created
- `jenkins.executor.proxy` created
- `jenkins.master` created and only refers to the Jenkins master installation
- `jenkins.master.source` created to refer to the full URL of the war download
- `jenkins.master.jvm_options` created
- `jenkins.master.jenkins_args` added
- `jenkins.master.url` -> `jenkins.master.endpoint`
- `jenkins.master.log_directory` created
- `jenkins.node` attributes have all been removed
- `jenkins.server` attributes have all been removed
- `jenkins.cli` has been removed
- `jenkins.java_home` has been changed to `jenkins.java` and accepts the full path to the java binary, not the JAVA_HOME
- `jenkins.iptables_allow` has been removed
- `jenkins.mirror` -> `jenkins.master.mirror`
- `jenkins.executor` created
- `jenkins.executor.timeout` created
- `jenkins.executor.private_key` created
- `jenkins.executor.proxy` created
- `jenkins.master` created and only refers to the Jenkins master installation
- `jenkins.master.source` created to refer to the full URL of the war download
- `jenkins.master.jvm_options` created
- `jenkins.master.jenkins_args` added
- `jenkins.master.url` -> `jenkins.master.endpoint`
- `jenkins.master.log_directory` created
- `jenkins.node` attributes have all been removed
- `jenkins.server` attributes have all been removed

- Removed Chef MiniTest handler

Expand Down
21 changes: 0 additions & 21 deletions libraries/_executor.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
#
# Cookbook:: jenkins
# Library:: executor
#
# Author:: Seth Vargo <[email protected]>
#
# Copyright:: 2013-2019, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'mixlib/shellout'
require 'shellwords'
require 'tempfile'
Expand Down
117 changes: 117 additions & 0 deletions libraries/_slave.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# attr_writer :exists
# attr_writer :connected
# attr_writer :online

module Jenkins
module Cookbook
module Slave
#
# Determine if the slave exists on the master. This value is set by
# the provider when the current resource is loaded.
#
# @return [Boolean]
#
def exists?
[email protected]? && @exists
end

#
# Determine if the slave is connected to the master. This value is
# set by the provider when the current resource is loaded.
#
# @return [Boolean]
#
def connected?
[email protected]? && @connected
end

#
# Determine if the slave is online. This value is set by the
# provider when the current resource is loaded.
#
# @return [Boolean]
#
def online?
[email protected]? && @online
end

def merge_preserved_labels!
new_resource.labels |= current_resource.labels.select { |i| i[/^prsrv_/] }
end

def do_create
# Preserve some labels...
merge_preserved_labels!
if current_resource.exists? && correct_config?
Chef::Log.info("#{new_resource} exists - skipping")
else
converge_by("Create #{new_resource}") do
executor.groovy! <<-EOH.gsub(/^ {12}/, '')
import hudson.model.*
import hudson.slaves.*
import jenkins.model.*
import jenkins.slaves.*

props = []
availability = #{convert_to_groovy(new_resource.availability)}
usage_mode = #{convert_to_groovy(new_resource.usage_mode)}
env_map = #{convert_to_groovy(new_resource.environment)}
labels = #{convert_to_groovy(new_resource.labels.sort.join(' '))}

// Compute the usage mode
if (usage_mode == 'normal') {
mode = Node.Mode.NORMAL
} else {
mode = Node.Mode.EXCLUSIVE
}

// Compute the retention strategy
if (availability == 'demand') {
retention_strategy =
new RetentionStrategy.Demand(
#{new_resource.in_demand_delay},
#{new_resource.idle_delay}
)
} else if (availability == 'always') {
retention_strategy = new RetentionStrategy.Always()
} else {
retention_strategy = RetentionStrategy.NOOP
}

// Create an entry in the prop list for all env vars
if (env_map != null) {
env_vars = new hudson.EnvVars(env_map)
entries = env_vars.collect {
k,v -> new EnvironmentVariablesNodeProperty.Entry(k,v)
}
props << new EnvironmentVariablesNodeProperty(entries)
}

// Launcher
#{launcher_groovy}

// Build the slave object
slave = new DumbSlave(
#{convert_to_groovy(new_resource.name)},
#{convert_to_groovy(new_resource.description)},
#{convert_to_groovy(new_resource.remote_fs)},
#{convert_to_groovy(new_resource.executors.to_s)},
mode,
labels,
launcher,
retention_strategy,
props
)

// Create or update the slave in the Jenkins instance
nodes = new ArrayList(Jenkins.instance.getNodes())
ix = nodes.indexOf(slave)
(ix >= 0) ? nodes.set(ix, slave) : nodes.add(slave)
Jenkins.instance.setNodes(nodes)
EOH
end
end
end
end
end
end
59 changes: 0 additions & 59 deletions libraries/command.rb

This file was deleted.

Loading