Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-at-redhat committed Oct 14, 2024
1 parent 1cba12c commit 1624d48
Show file tree
Hide file tree
Showing 32 changed files with 633 additions and 162 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/coverage_reporting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ jobs:
run: find /tmp/receptor-testing -name controlsock -delete

- name: Artifact receptor data
uses: actions/[email protected].0
uses: actions/[email protected].3
if: ${{ failure() }}
with:
name: test-logs
path: /tmp/receptor-testing

- name: Archive receptor binary
uses: actions/[email protected].0
uses: actions/[email protected].3
with:
name: receptor
path: /usr/local/bin/receptor
8 changes: 4 additions & 4 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on: # yamllint disable-line rule:truthy

env:
DESIRED_GO_VERSION: '1.20'
DESIRED_GOLANGCI_LINT_VERSION: 'v1.56'
DESIRED_GOLANGCI_LINT_VERSION: 'v1.60'
DESIRED_PYTHON_VERSION: '3.12'

jobs:
Expand Down Expand Up @@ -72,14 +72,14 @@ jobs:
run: find /tmp/receptor-testing -name controlsock -delete

- name: Artifact receptor data for ${{ matrix.go-version }}
uses: actions/[email protected].0
uses: actions/[email protected].3
if: ${{ failure() }}
with:
name: test-logs-${{ matrix.go-version }}
path: /tmp/receptor-testing

- name: Archive receptor binary for ${{ matrix.go-version }}
uses: actions/[email protected].0
uses: actions/[email protected].3
with:
name: receptor-${{ matrix.go-version }}
path: /usr/local/bin/receptor
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
run: sudo chmod a+x /usr/local/bin/receptor

- name: Set up nox
uses: wntrblm/nox@2024.04.15
uses: wntrblm/nox@2024.10.09
with:
python-versions: ${{ env.DESIRED_PYTHON_VERSION }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-nox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: sudo chmod a+x /usr/local/bin/receptor

- name: Set up nox
uses: wntrblm/nox@2024.04.15
uses: wntrblm/nox@2024.10.09
with:
python-versions: ${{ inputs.python-version }}

Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.
Expand All @@ -12,7 +13,7 @@ on:
schedule:
- cron: '41 15 * * 4'
push:
branches: [ "devel" ]
branches: ["devel"]

# Declare default permissions as read only.
permissions: read-all
Expand All @@ -32,12 +33,12 @@ jobs:

steps:
- name: "Checkout code"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
with:
results_file: results.sarif
results_format: sarif
Expand All @@ -59,7 +60,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
uses: actions/upload-artifact@184d73b71b93c222403b2e7f1ffebe4508014249 # v4.4.2
with:
name: SARIF file
path: results.sarif
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/test-reporting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
name: Generate junit test report

on: # yamllint disable-line rule:truthy
pull_request: # yamllint disable-line rule:empty-values
push:
branches: [devel]

env:
DESIRED_GO_VERSION: '1.20'

jobs:
go_test_coverage:
name: go test coverage
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.DESIRED_GO_VERSION }}

- name: build and install receptor
run: |
make build-all
sudo cp ./receptor /usr/local/bin/receptor
- name: Download kind binary
run: curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64 && chmod +x ./kind

- name: Create k8s cluster
run: ./kind create cluster

- name: Interact with the cluster
run: kubectl get nodes

- name: Install go junit reporting
run: go install github.com/jstemmer/go-junit-report/v2@latest

- name: Run receptor tests
run: go test -v 2>&1 ./... | go-junit-report > report.xml

- name: Upload test results to dashboard
if: >-
!cancelled()
&& github.event_name == 'push'
&& github.repository == 'ansible/receptor'
&& github.ref_name == github.event.repository.default_branch
run: >-
curl -v --user "${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_USER }}:${{ secrets.PDE_ORG_RESULTS_UPLOAD_PASSWORD }}"
--form "[email protected]"
--form "component_name=receptor"
--form "git_commit_sha=${{ github.sha }}"
--form "git_repository_url=https://github.com/${{ github.repository }}"
"${{ vars.PDE_ORG_RESULTS_AGGREGATOR_UPLOAD_URL }}/api/results/upload/"
- name: get k8s logs
if: ${{ failure() }}
run: .github/workflows/artifact-k8s-logs.sh

- name: remove sockets before archiving logs
if: ${{ failure() }}
run: find /tmp/receptor-testing -name controlsock -delete

- name: Artifact receptor data
uses: actions/[email protected]
if: ${{ failure() }}
with:
name: test-logs
path: /tmp/receptor-testing

- name: Archive receptor binary
uses: actions/[email protected]
with:
name: receptor
path: /usr/local/bin/receptor
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ linters:
- gofumpt
- goheader
- goimports
- gomoddirectives
- gomodguard
- gosec
- gosimple
Expand Down Expand Up @@ -101,6 +100,7 @@ linters-settings:
- "k8s.io/client-go/tools/remotecommand"
- "github.com/quic-go/quic-go"
- "github.com/quic-go/quic-go/logging"
- "github.com/AaronH88/quic-go"

issues:
# Dont commit the following line.
Expand Down
4 changes: 4 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sonar.python.version=3.8, 3.9, 3.11, 3.12
sonar.sources=.
sonar.test.inclusions=**/*_test.go, receptorctl/tests/
sonar.tests=.
91 changes: 74 additions & 17 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ type Runer interface {
Run() error
}

type Reloader interface {
Reload() error
}

type ReceptorConfig struct {
// Used pointer structs to apply defaults to config
Node *types.NodeCfg
Trace logger.TraceCfg
LocalOnly backends.NullBackendCfg `mapstructure:"local-only"`
LogLevel *logger.LoglevelCfg `mapstructure:"log-level"`
ControlServices []*controlsvc.CmdlineConfigUnix `mapstructure:"control-services"`
TCPPeers []*backends.TCPDialerCfg `mapstructure:"tcp-peers"`
UDPPeers []*backends.UDPDialerCfg `mapstructure:"udp-peers"`
WSPeers []*backends.WebsocketDialerCfg `mapstructure:"ws-peers"`
TCPListeners []*backends.TCPListenerCfg `mapstructure:"tcp-listeners"`
UDPListeners []*backends.UDPListenerCfg `mapstructure:"udp-listeners"`
WSListeners []*backends.WebsocketListenerCfg `mapstructure:"ws-listeners"`
TLSClients []netceptor.TLSClientConfig `mapstructure:"tls-clients"`
TLSServer []netceptor.TLSServerConfig `mapstructure:"tls-servers"`
WorkCommands []workceptor.CommandWorkerCfg `mapstructure:"work-commands"`
Expand All @@ -63,28 +60,48 @@ type CertificatesConfig struct {
SignReq []certificates.SignReqConfig `mapstructure:"cert-signreqs"`
}

type BackendConfig struct {
TCPListeners []*backends.TCPListenerCfg `mapstructure:"tcp-listeners"`
UDPListeners []*backends.UDPListenerCfg `mapstructure:"udp-listeners"`
WSListeners []*backends.WebsocketListenerCfg `mapstructure:"ws-listeners"`
TCPPeers []*backends.TCPDialerCfg `mapstructure:"tcp-peers"`
UDPPeers []*backends.UDPDialerCfg `mapstructure:"udp-peers"`
WSPeers []*backends.WebsocketDialerCfg `mapstructure:"ws-peers"`
LocalOnly backends.NullBackendCfg `mapstructure:"local-only"`
}

func PrintPhaseErrorMessage(configName string, phase string, err error) {
fmt.Printf("ERROR: %s for %s on %s phase\n", err, configName, phase)
}

func ParseConfigs(configFile string) (*ReceptorConfig, *CertificatesConfig, error) {
if configFile == "" && viper.ConfigFileUsed() == "" {
fmt.Fprintln(os.Stderr, "Could not locate config file (default is $HOME/receptor.yaml)")
os.Exit(1)
}
func ParseReceptorConfig(configFile string) (*ReceptorConfig, error) {
var receptorConfig ReceptorConfig
var certifcatesConfig CertificatesConfig
err := viper.Unmarshal(&receptorConfig)
if err != nil {
return nil, nil, err
return nil, err
}

err = viper.Unmarshal(&certifcatesConfig)
return &receptorConfig, nil
}

func ParseCertificatesConfig(configFile string) (*CertificatesConfig, error) {
var certifcatesConfig CertificatesConfig
err := viper.Unmarshal(&certifcatesConfig)
if err != nil {
return nil, err
}

return &certifcatesConfig, nil
}

func ParseBackendConfig(configFile string) (*BackendConfig, error) {
var backendConfig BackendConfig
err := viper.Unmarshal(&backendConfig)
if err != nil {
return nil, nil, err
return nil, err
}

return &receptorConfig, &certifcatesConfig, nil
return &backendConfig, nil
}

func isConfigEmpty(v reflect.Value) bool {
Expand Down Expand Up @@ -157,6 +174,46 @@ func RunPhases(phase string, v reflect.Value) {
}
}

// ReloadServices iterates through key/values calling reload on applicable services.
func ReloadServices(v reflect.Value) {
for i := 0; i < v.NumField(); i++ {
// if the services is not initialised, skip
if reflect.Value.IsZero(v.Field(i)) {
continue
}

var err error
switch v.Field(i).Kind() {
case reflect.Slice:
// iterate over all the type fields
for j := 0; j < v.Field(i).Len(); j++ {
serviceItem := v.Field(i).Index(j).Interface()
switch c := serviceItem.(type) {
// check to see if the selected type field satisfies reload
// call reload on cfg object
case Reloader:
err = c.Reload()
if err != nil {
PrintPhaseErrorMessage(v.Type().Name(), "reload", err)
}
// if cfg object does not satisfy, do nothing
default:
}
}
// runs for non slice fields
default:
switch c := v.Field(i).Interface().(type) {
case Reloader:
err = c.Reload()
if err != nil {
PrintPhaseErrorMessage(v.Type().Name(), "reload", err)
}
default:
}
}
}
}

func RunConfigV1() {
cl := cmdline.NewCmdline()
cl.AddConfigType("node", "Specifies the node configuration of this instance", types.NodeCfg{}, cmdline.Required, cmdline.Singleton)
Expand Down
Loading

0 comments on commit 1624d48

Please sign in to comment.