Skip to content

Commit

Permalink
Rename to rhc-worker-script
Browse files Browse the repository at this point in the history
Signed-off-by: Rodolfo Olivieri <[email protected]>
  • Loading branch information
r0x0d committed Aug 8, 2023
1 parent 448d17f commit 3cb6270
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
platforms: 'linux/amd64'
package: 'src'
name: 'rhc-worker-${{ steps.tagName.outputs.tag }}'
name: 'rhc-worker-script-${{ steps.tagName.outputs.tag }}'
compress: 'true'
dest: 'dist'

Expand Down
22 changes: 11 additions & 11 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
specfile_path: packaging/rhc-worker.spec
upstream_package_name: rhc-worker
downstream_package_name: rhc-worker
upstream_project_url: https://github.com/oamg/rhc-worker
specfile_path: packaging/rhc-worker-script.spec
upstream_package_name: rhc-worker-script
downstream_package_name: rhc-worker-script
upstream_project_url: https://github.com/oamg/rhc-worker-script

srpm_build_deps: [golang, make]

Expand All @@ -10,22 +10,22 @@ jobs:
- job: copr_build
enable_net: true
owner: "@oamg"
project: "rhc-worker"
project: "rhc-worker-script"
targets:
- epel-7-x86_64
trigger: pull_request
actions:
# do not get the version from a tag (git describe) but from the spec file
get-current-version:
- grep -oP '^Version:\s+\K\S+' packaging/rhc-worker.spec
- grep -oP '^Version:\s+\K\S+' packaging/rhc-worker-script.spec
create-archive:
- "make distribution-tarball"
- bash -c "ls -1 ./rhc-worker-*.tar.gz"
- bash -c "ls -1 ./rhc-worker-script-*.tar.gz"

- job: copr_build
enable_net: true
owner: "@oamg"
project: "rhc-worker"
project: "rhc-worker-script"
targets:
- epel-7-x86_64
trigger: commit
Expand All @@ -34,11 +34,11 @@ jobs:
# bump spec so we get release starting with 2 and hence all the default branch builds will
# have higher NVR than all the PR builds
post-upstream-clone:
- rpmdev-bumpspec --comment='latest upstream build' ./packaging/rhc-worker.spec
- rpmdev-bumpspec --comment='latest upstream build' ./packaging/rhc-worker-script.spec

# do not get the version from a tag (git describe) but from the spec file
get-current-version:
- grep -oP '^Version:\s+\K\S+' packaging/rhc-worker.spec
- grep -oP '^Version:\s+\K\S+' packaging/rhc-worker-script.spec
create-archive:
- "make distribution-tarball"
- bash -c "ls -1 ./rhc-worker-*.tar.gz"
- bash -c "ls -1 ./rhc-worker-script-*.tar.gz"
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ can run a series of pre-defined hooks against our codebase to keep it clean and
maintainable. Here is an example of output from `pre-commit` being run:

```
(.venv3) [rhc-worker]$ pre-commit run --all-files
(.venv3) [rhc-worker-script]$ pre-commit run --all-files
golangci-lint............................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Project constants
VERSION ?= 0.2
PKGNAME ?= rhc-worker
PKGNAME ?= rhc-worker-script
GO_SOURCES := $(wildcard src/*.go)
PYTHON ?= python3
PIP ?= pip3
Expand Down Expand Up @@ -45,7 +45,7 @@ clean:

build: $(GO_SOURCES)
mkdir -p build
CGO_ENABLED=0 go build -o build/rhc-worker $^
CGO_ENABLED=0 go build -o build/rhc-worker-script $^

distribution-tarball:
go mod vendor
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
![Tests](https://github.com/oamg/rhc-worker/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/github/oamg/rhc-worker/branch/main/graph/badge.svg?token=6MRLOJS2SJ)](https://codecov.io/github/oamg/rhc-worker)
![Tests](https://github.com/oamg/rhc-worker-script/actions/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/github/oamg/rhc-worker-script/branch/main/graph/badge.svg?token=6MRLOJS2SJ)](https://codecov.io/github/oamg/rhc-worker-script)

# RHC Worker

Remote Host Configuration (rhc) worker for executing scripts on hosts
managed by Red Hat Insights. Interpreter used to execute the script is defined inside the supplied yaml file - served by insights.

- [RHC Worker Bash](#rhc-worker)
- [RHC Worker Bash](#rhc-worker-script)
- [General workflow of the worker](#general-workflow-of-the-worker)
- [Getting started with local development](#getting-started-with-local-development)
- [Publish first message](#publish-first-message)
- [Worker playbooks](#worker-playbooks)
- [Custom playbook](#custom-playbook)
- [Convert2RHEL Playbook](#convert2rhel-playbook)
- [FAQ](#faq)
- [Are there special environment variables used by `rhc-worker`?](#are-there-special-environment-variables-used-by-rhc-worker)
- [Can I change behavior of `rhc-worker`?](#can-i-change-behavior-of-rhc-worker)
- [Can I change the location of `rhc-worker` config?](#can-i-change-the-location-of-rhc-worker-config)
- [Are there special environment variables used by `rhc-worker-script`?](#are-there-special-environment-variables-used-by-rhc-worker-script)
- [Can I change behavior of `rhc-worker-script`?](#can-i-change-behavior-of-rhc-worker-script)
- [Can I change the location of `rhc-worker-script` config?](#can-i-change-the-location-of-rhc-worker-script-config)
- [Contact](#contact)
- [Package maintainers](#package-maintainers)

Expand Down Expand Up @@ -84,18 +84,18 @@ vagrant ssh -- -t 'rhcd --log-level trace \
### Worker playbooks

There is an [example bash playbook](
https://github.com/oamg/rhc-worker/blob/main/development/nginx/data/example_bash.yaml)
https://github.com/oamg/rhc-worker-script/blob/main/development/nginx/data/example_bash.yaml)
available under `development/nginx/data`, with a minimal bash script to use
during the worker execution.

If there's a need to test any other playbook provided in this repository, one
must change what playbook will be used during the message consumption in the
[mqtt_publish.py](https://github.com/oamg/rhc-worker/blob/main/development/python/mqtt_publish.py#L22)
[mqtt_publish.py](https://github.com/oamg/rhc-worker-script/blob/main/development/python/mqtt_publish.py#L22)
file with the name that corresponds the ones present in `development/nginx/data`. Currently, the ones available are:

1. [example_bash.yaml](https://github.com/oamg/rhc-worker/blob/main/development/nginx/data/example_bash.yaml)
2. [example_python.yaml](https://github.com/oamg/rhc-worker/blob/main/development/nginx/data/example_python.yaml)
3. [convert2rhel.yaml](https://github.com/oamg/rhc-worker/blob/main/development/nginx/data/convert2rhel.yaml)
1. [example_bash.yaml](https://github.com/oamg/rhc-worker-script/blob/main/development/nginx/data/example_bash.yaml)
2. [example_python.yaml](https://github.com/oamg/rhc-worker-script/blob/main/development/nginx/data/example_python.yaml)
3. [convert2rhel.yaml](https://github.com/oamg/rhc-worker-script/blob/main/development/nginx/data/convert2rhel.yaml)

#### Custom playbook

Expand All @@ -113,23 +113,23 @@ A specialized [Convert2RHEL](https://github.com/oamg/convert2rhel) playbook can

## FAQ

### Are there special environment variables used by `rhc-worker`?
### Are there special environment variables used by `rhc-worker-script`?

There is one special variable that must be set in order to run our worker and that is `YGG_SOCKET_ADDR`, this variable value is set by `rhcd` via `--socket-addr` option.

Other than that there are no special variables, however if downloaded yaml file contained `content_vars` (like the example above), then before the execution of the bash script (`content`) all such variables are set as environment variables and prefixed with `RHC_WORKER_`, after script execution is done they are unset.

### Can I change behavior of `rhc-worker`?
### Can I change behavior of `rhc-worker-script`?

Yes, some values can be changed if config exists at `/etc/rhc/workers/rhc-worker.yml`, **the config must have valid yaml format**, see all available fields below.
Yes, some values can be changed if config exists at `/etc/rhc/workers/rhc-worker-script.yml`, **the config must have valid yaml format**, see all available fields below.

Example of full config (with default values):

```yaml
# rhc-worker configuration
# rhc-worker-script configuration

# recipient directive to register with dispatcher
directive: "rhc-worker"
directive: "rhc-worker-script"

# whether to verify incoming yaml files
verify_yaml: true
Expand All @@ -138,10 +138,10 @@ verify_yaml: true
insights_core_gpg_check: true

# temporary directory in which the temporary files with executed bash scripts are created
temporary_worker_directory: "/var/lib/rhc-worker"
temporary_worker_directory: "/var/lib/rhc-worker-script"
```
### Can I change the location of `rhc-worker` config?
### Can I change the location of `rhc-worker-script` config?

No, not right now. If you want this feature please create an issue or upvote already existing issue.

Expand Down
2 changes: 1 addition & 1 deletion development/python/mqtt_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_ip_address():
"message_id": str(uuid.uuid4()),
"version": 1,
"sent": "2021-01-12T14:58:13+00:00", # str(datetime.datetime.now().isoformat()),
"directive": 'rhc-worker',
"directive": 'rhc-worker-script',
"content": f'http://{get_ip_address()}:8000/data/{SERVED_FILENAME}',
"metadata": {
"correlation_id": "00000000-0000-0000-0000-000000000000",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/oamg/rhc-worker
module github.com/oamg/rhc-worker-script

go 1.16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
%define debug_package %{nil}

%global repo_orgname oamg
%global repo_name rhc-worker
%global repo_name rhc-worker-script
%global rhc_libexecdir %{_libexecdir}/rhc
%{!?_root_sysconfdir:%global _root_sysconfdir %{_sysconfdir}}
%global rhc_worker_conf_dir %{_root_sysconfdir}/rhc/workers
Expand Down Expand Up @@ -58,7 +58,7 @@ popd


%install
# Create a temporary directory /var/lib/rhc-worker - used mainly for storing temporary files
# Create a temporary directory /var/lib/rhc-worker-script - used mainly for storing temporary files
install -d %{buildroot}%{_sharedstatedir}/%{repo_name}/

install -D -m 755 _gopath/src/%{repo_name}-%{version}/%{repo_name}-%{version} %{buildroot}%{rhc_libexecdir}/%{repo_name}
Expand Down
4 changes: 2 additions & 2 deletions rhc-worker.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# recipient directive to register with dispatcher
directive: "rhc-worker"
directive: "rhc-worker-script"

# whether to verify incoming yaml files
verify_yaml: false
Expand All @@ -8,4 +8,4 @@ verify_yaml: false
insights_core_gpg_check: false

# temporary directory in which the temporary script will be placed and executed.
temporary_worker_directory: "/var/lib/rhc-worker"
temporary_worker_directory: "/var/lib/rhc-worker-script"
2 changes: 1 addition & 1 deletion src/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

var sosReportFolder = "/etc/sos.extras.d"
var sosReportFile = "rhc-worker-logs"
var sosReportFile = "rhc-worker-script-logs"

// SetupLogger sets up the logger for the application and returns the log file.
// It creates a log folder if it doesn't exist, opens a log file, sets the log level
Expand Down
10 changes: 5 additions & 5 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
)

// Initialized in main
const configFilePath = "/etc/rhc/workers/rhc-worker.yml"
const logDir = "/var/log/rhc-worker"
const logFileName = "rhc-worker.log"
const configFilePath = "/etc/rhc/workers/rhc-worker-script.yml"
const logDir = "/var/log/rhc-worker-script"
const logFileName = "rhc-worker-script.log"

var yggdDispatchSocketAddr string
var config *Config
Expand Down Expand Up @@ -52,11 +52,11 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

// Register as a handler of the "rhc-worker" type.
// Register as a handler of the "rhc-worker-script" type.
r, err := c.Register(
ctx,
&pb.RegistrationRequest{
Handler: "rhc-worker",
Handler: "rhc-worker-script",
Pid: int64(os.Getpid()),
DetachedContent: true,
})
Expand Down
10 changes: 5 additions & 5 deletions src/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func writeFileToTemporaryDir(data []byte, temporaryWorkerDirectory string) strin
}
}

file, err := os.CreateTemp(temporaryWorkerDirectory, "rhc-worker-")
file, err := os.CreateTemp(temporaryWorkerDirectory, "rhc-worker-script")
if err != nil {
log.Errorln("Failed to create temporary file: ", err)
}
Expand Down Expand Up @@ -61,7 +61,7 @@ func getOutputFile(stdout string, correlationID string, contentType string) (*by
writer := multipart.NewWriter(body)

h := make(textproto.MIMEHeader)
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, "file", "rhc-worker-output.tar.gz"))
h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, "file", "rhc-worker-script-output.tar.gz"))
h.Set("Content-Type", contentType)

part, err := writer.CreatePart(h)
Expand Down Expand Up @@ -104,7 +104,7 @@ type Config struct {
func setDefaultValues(config *Config) {
// Set default values for string and boolean fields if they are nil (not present in the YAML)
if config.Directive == nil {
defaultDirectiveValue := "rhc-worker"
defaultDirectiveValue := "rhc-worker-script"
config.Directive = &defaultDirectiveValue
}

Expand All @@ -119,7 +119,7 @@ func setDefaultValues(config *Config) {
}

if config.TemporaryWorkerDirectory == nil {
defaultTemporaryWorkerDirectoryValue := "/var/lib/rhc-worker"
defaultTemporaryWorkerDirectoryValue := "/var/lib/rhc-worker-script"
config.TemporaryWorkerDirectory = &defaultTemporaryWorkerDirectoryValue
}
}
Expand All @@ -141,7 +141,7 @@ func loadYAMLConfig(filePath string) *Config {
}

// Load config from given filepath, if config doesn't exist then default config values are used
// Directive = rhc-worker
// Directive = rhc-worker-script
// VerifyYAML = "1"
// InsightsCoreGPGCheck = "1"
func loadConfigOrDefault(filePath string) *Config {
Expand Down
10 changes: 5 additions & 5 deletions src/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,23 @@ func boolPtr(b bool) *bool {

// Test YAML data
const validYAMLData = `
directive: "rhc-worker"
directive: "rhc-worker-script"
verify_yaml: true
verify_yaml_version_check: true
insights_core_gpg_check: true
temporary_worker_directory: "/var/lib/rhc-worker"
temporary_worker_directory: "/var/lib/rhc-worker-script"
`

const validYAMLDataMissingValues = `
directive: "rhc-worker"
directive: "rhc-worker-script"
`

func TestLoadConfigOrDefault(t *testing.T) {
expectedConfig := &Config{
Directive: strPtr("rhc-worker"),
Directive: strPtr("rhc-worker-script"),
VerifyYAML: boolPtr(true),
InsightsCoreGPGCheck: boolPtr(true),
TemporaryWorkerDirectory: strPtr("/var/lib/rhc-worker"),
TemporaryWorkerDirectory: strPtr("/var/lib/rhc-worker-script"),
}

testCases := []struct {
Expand Down

0 comments on commit 3cb6270

Please sign in to comment.