Skip to content

Commit

Permalink
remove orchestration support due to unsolvable issues
Browse files Browse the repository at this point in the history
Removed all support for orchestration at this time due to the following
reasons:

* Continuous issues with args not being properly passed to bolt or
  executed by bolt. This issue is happening outside of the written code
  and a RCA was not able to be found.
* No other orchestrators are ready
* Make room to add `g10k` support to webhook-go
* Allow focus to shift to getting the old webhook in `puppet-r10k`
  replaced with webhook-go
  • Loading branch information
dhollinger committed Jan 6, 2023
1 parent cc11777 commit 3f50673
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 325 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ binary: ## Build a local binary
@cp dist/$(NAME)_$(GOOS)_$(GOARCH)_$(VERSION)/$(NAME) bin/

run: ## Run webhook-go
@cp webhook.yml.example webhook.yml
@go run main.go
@go run main.go --config ./webhook.yml

clean: ## Clean up build
@echo "Cleaning Go environment..."
Expand Down
76 changes: 0 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ chatops:
user: r10kbot
auth_token: 12345
server_uri: "https://rocketchat.local"
orchestration:
enabled: true
type: bolt
user: webhook
bolt:
transport: local
targets:
- localhost
r10k:
config_path: /etc/puppetlabs/r10k/r10k.yaml
default_branch: main
Expand Down Expand Up @@ -153,74 +145,6 @@ Type: string
Description: The ChatOps service API URI to send the message to.
Default: nil

### Orchestration

#### `enabled`

Type: boolean
Description: Enable/Disable orchestration support
Default: false

#### `type`

Type: string
Description: Which orchestration tool to use. Currently only supports `bolt`.
Default: nil

#### `user`

Type: string
Description: User to authenticate to the target as.
Default: nil

#### `password`

Type: string
Description: Password for authentication use.
Default: nil

#### `bolt`

Type: hash
Description: Hash of Puppet Bolt specific settings.
Default: `nil`

##### `transport`

Type: string
Description: What kind of bolt network transport protocol to use. Supported types: [`local`, `ssh`] with more coming soon.
Default: `nil`

##### `targets`

Type: array
Description: A list of target nodes that Bolt will attempt to run `r10k` on.
Default: []

##### `concurrency`

Type: integer
Description: Maximum number of simultaneous connections.
Default: 100

##### `run_as`

Type: string
Description: User to run the `r10k` command as.
Default: nil

##### `sudo_password`

Type: string
Description: The password to use when using `sudo` to run `r10k` as the `run_as` user.
Default: nil

##### `HostKeyCheck`

Type: boolean
Description: Enable/Disable SSH host key checking
Default: false

### r10k options

#### `config_path`
Expand Down
21 changes: 8 additions & 13 deletions api/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import (
type EnvironmentController struct{}

// DeployEnvironment takes in the current Gin context and parses the request
// data into a variable then executes the r10k environment deploy either through
// an orchestrator defined in the Orchestration library or a direct local execution
// of the r10k deploy environment command
// data into a variable then executes the r10k environment deploy as direct
// local execution of the r10k deploy environment command
func (e EnvironmentController) DeployEnvironment(c *gin.Context) {
var data parsers.Data
var h helpers.Helper
Expand Down Expand Up @@ -57,20 +56,20 @@ func (e EnvironmentController) DeployEnvironment(c *gin.Context) {

// Set additional optional r10k options if they are set
if conf.R10k.Verbose {
cmd = append(cmd, "-v")
}
if conf.R10k.DeployModules {
cmd = append(cmd, "-m")
cmd = append(cmd, "--verbose")
}
if conf.R10k.GenerateTypes {
cmd = append(cmd, "--generate-types")
}
if conf.R10k.DeployModules {
cmd = append(cmd, "--modules")
}

// Pass the command to the execute function and act on the result and any error
// that is returned
//
// On an error this will:
// * Log the error, orchestration type, and command
// * Log the error and command
// * Respond with an HTTP 500 error and return the command result in JSON format
// * Abort the request
// * Notify ChatOps service if enabled
Expand All @@ -79,11 +78,7 @@ func (e EnvironmentController) DeployEnvironment(c *gin.Context) {
// * Respond with an HTTP 202 and the result in JSON format
res, err := execute(cmd)
if err != nil {
if conf.Orchestration.Enabled {
log.Errorf("orchestrator `%s` failed to execute command `%s` with error: `%s` `%s`", *conf.Orchestration.Type, cmd, err, res)
} else {
log.Errorf("failed to execute local command `%s` with error: `%s` `%s`", cmd, err, res)
}
log.Errorf("failed to execute local command `%s` with error: `%s` `%s`", cmd, err, res)

c.JSON(http.StatusInternalServerError, res)
c.Abort()
Expand Down
41 changes: 1 addition & 40 deletions api/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ package api

import (
"os/exec"
"strings"

"github.com/voxpupuli/webhook-go/config"
"github.com/voxpupuli/webhook-go/lib/chatops"
"github.com/voxpupuli/webhook-go/lib/orchestrators"
)

func chatopsSetup() *chatops.ChatOps {
Expand All @@ -22,45 +20,8 @@ func chatopsSetup() *chatops.ChatOps {
return &c
}

// Determine if orchestration is enabled and either pass the cmd string slice to a
// the orchestrationExec function or localExec function.
//
// This returns an interface of the result of the execution and an error
func execute(cmd []string) (interface{}, error) {
conf := config.GetConfig()
var res interface{}
var err error
if conf.Orchestration.Enabled {
res, err = orchestrationExec(cmd)
if err != nil {
return res, err
}
} else {
res, err = localExec(cmd)
if err != nil {
return res, err
}
}
return res, nil
}

func orchestrationExec(cmd []string) (interface{}, error) {
command := "\""
for i := range cmd {
command = command + cmd[i] + " "
}
command = strings.TrimSuffix(command, " ")
command = command + "\""

res, err := orchestrators.Deploy(command)
if err != nil {
return res, err
}

return res, nil
}

func localExec(cmd []string) (string, error) {
args := cmd[1:]
command := exec.Command(cmd[0], args...)

Expand All @@ -69,5 +30,5 @@ func localExec(cmd []string) (string, error) {
return string(res), err
}

return string(res), nil
return res, nil
}
11 changes: 3 additions & 8 deletions api/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type ModuleController struct{}

// DeployModule takes int the current Gin context and parses the request
// data into a variable then executes the r10k module deploy either through
// an orchestrator defined in the orchestration library or a direct local execution
// of the r10k deploy module command
// a direct local execution of the r10k deploy module command
func (m ModuleController) DeployModule(c *gin.Context) {
var data parsers.Data
var h helpers.Helper
Expand Down Expand Up @@ -55,7 +54,7 @@ func (m ModuleController) DeployModule(c *gin.Context) {
// that is returned
//
// On an error this will:
// * Log the error, orchestration type, and command
// * Log the error and command
// * Respond with an HTTP 500 error and return the command result in JSON format
// * Abort the request
// * Notify ChatOps service if enabled
Expand All @@ -64,11 +63,7 @@ func (m ModuleController) DeployModule(c *gin.Context) {
// * Respond with an HTTP 202 and the result in JSON format
res, err := execute(cmd)
if err != nil {
if conf.Orchestration.Enabled {
log.Errorf("orchestrator `%s` failed to execute command `%s` with error: `%s` `%s`", *conf.Orchestration.Type, cmd, err, res)
} else {
log.Errorf("failed to execute local command `%s` with error: `%s` `%s`", cmd, err, res)
}
log.Errorf("failed to execute local command `%s` with error: `%s` `%s`", cmd, err, res)

c.JSON(http.StatusInternalServerError, res)
c.Abort()
Expand Down
26 changes: 9 additions & 17 deletions build/webhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,16 @@ server:
enabled: false
certificate: ""
key: ""
# chatops:
# enabled: false
# service: slack
# channel: "#general"
# user: r10kbot
# auth_token: 12345
# server_uri: "https://rocketchat.local"
chatops:
enabled: false
service: slack
channel: "#general"
user: r10kbot
auth_token: 12345
server_uri: "https://rocketchat.local"
r10k:
config_path: /etc/puppetlabs/r10k/r10k.yaml
# default_branch: webhook_test
default_branch: webhook_test
allow_uppercase: false
verbose: true
# orchestration:
# enabled: false
# type: bolt
# user: dhollinger
# bolt:
# transport: local
# targets:
# - localhost
# host_key_check: false
generate_types: false
12 changes: 0 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ type Config struct {
AuthToken string `mapstructure:"auth_token"`
ServerUri string `mapstructure:"server_uri"`
} `mapstructure:"chatops"`
Orchestration struct {
Enabled bool `mapstructure:"enabled"`
Type *string `mapstructure:"type"`
Bolt *struct {
Transport *string `mapstructure:"transport"`
Targets []string `mapstructure:"targets"`
Concurrency *int64 `mapstructure:"concurrency"`
HostKeyCheck bool `mapstructure:"host_key_check"`
} `mapstructure:"bolt"`
} `mapstructure:"orchestration"`
R10k struct {
CommandPath string `mapstructure:"command_path"`
ConfigPath string `mapstructure:"config_path"`
Expand Down Expand Up @@ -91,8 +81,6 @@ func setDefaults(v *viper.Viper) *viper.Viper {
v.SetDefault("r10k.verbose", true)
v.SetDefault("r10k.deploy_modules", true)
v.SetDefault("r10k.generate_types", true)
v.SetDefault("orchestration.enabled", false)
v.SetDefault("orchestration.bolt.host_key_check", false)

return v
}
Expand Down
Loading

0 comments on commit 3f50673

Please sign in to comment.