Skip to content

Commit

Permalink
Merge branch 'main' into ash/daemonset-exec
Browse files Browse the repository at this point in the history
  • Loading branch information
hedge-sparrow authored Nov 1, 2024
2 parents 92e215d + 544a700 commit 5791595
Show file tree
Hide file tree
Showing 73 changed files with 4,998 additions and 1,184 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_epic.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ labels: 'epic'

# Design Proposal

Link to the [proposal](https://github.com/replicatedhq/troubleshoot/tree/main/design/template.md)
Link to the [proposal](https://github.com/replicatedhq/troubleshoot/tree/main/docs/design/template.md)

# Definition of done

Expand Down
25 changes: 15 additions & 10 deletions .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,32 @@ concurrency:
jobs:
fail_if_pull_request_is_draft:
if: github.event.pull_request.draft == true
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Fails in order to indicate that pull request needs to be marked as ready to review and unit tests workflow needs to pass.
run: exit 1

test:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: setup env
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash

- uses: actions/checkout@v4

- run: make test
- name: Run linters
run: make install-golangci-lint lint
- name: Run tests
run: make test

test-integration:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
Expand Down Expand Up @@ -79,7 +81,10 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: make check-schemas
path: github.com/replicatedhq/troubleshoot
- run: |
cd github.com/replicatedhq/troubleshoot
make check-schemas
compile-preflight:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -386,4 +391,4 @@ jobs:
# if the validate-pr-tests job was successful, this job will succeed
- name: succeed if validate-pr-tests job succeeded
if: needs.validate-pr-tests.result == 'success'
run: echo "Validation succeeded"
run: echo "Validation succeeded"
9 changes: 0 additions & 9 deletions .github/workflows/license.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21

- name: Install Go deps
run: go mod download

- name: Install trivy
run: |
wget https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-64bit.deb
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

run:
allow-parallel-runners: true
timeout: 30s
timeout: 10m

linters:
enable:
Expand All @@ -11,3 +11,5 @@ linters:
- gofmt
- gosec
- govet
disable:
- errcheck
24 changes: 15 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ VERSION_PACKAGE = github.com/replicatedhq/troubleshoot/pkg/version
VERSION ?=`git describe --tags --dirty`
DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
RUN?=""
GOLANGCI_LINT_VERSION ?= "v1.61.0"

GIT_TREE = $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
ifneq "$(GIT_TREE)" ""
Expand Down Expand Up @@ -34,7 +35,8 @@ define LDFLAGS
"
endef

BUILDFLAGS = -tags "netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp" -installsuffix netgo
BUILDTAGS = "netgo containers_image_ostree_stub exclude_graphdriver_devicemapper exclude_graphdriver_btrfs containers_image_openpgp"
BUILDFLAGS = -tags ${BUILDTAGS} -installsuffix netgo
BUILDPATHS = ./pkg/... ./cmd/... ./internal/...
E2EPATHS = ./test/e2e/...
TESTFLAGS ?= -v -coverprofile cover.out
Expand Down Expand Up @@ -131,7 +133,7 @@ generate: controller-gen client-gen
$(CONTROLLER_GEN) \
object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/...
$(CLIENT_GEN) \
--output-base=./../../../ \
--output-base=$$(pwd)/../../../ \
--output-package=github.com/replicatedhq/troubleshoot/pkg/client \
--clientset-name troubleshootclientset \
--input-base github.com/replicatedhq/troubleshoot/pkg/apis \
Expand All @@ -145,14 +147,14 @@ openapischema: controller-gen
controller-gen crd +output:dir=./config/crds paths=./pkg/apis/troubleshoot/v1beta2

check-schemas: generate schemas
@if [ -n "$(shell git status --short)" ]; then \
@if [ -n "$$(git status --short)" ]; then \
echo -e "\033[31mThe git repo is dirty :( Ensure all generated files are committed e.g CRD schema files\033[0;m"; \
git status --short; \
exit 1; \
fi

.PHONY: schemas
schemas: fmt vet openapischema bin/schemagen
schemas: openapischema bin/schemagen
./bin/schemagen --output-dir ./schemas

bin/schemagen:
Expand Down Expand Up @@ -236,12 +238,16 @@ scan:
./

.PHONY: lint
lint:
golangci-lint run --new -c .golangci.yaml ${BUILDPATHS}
lint: vet
golangci-lint run --new -c .golangci.yaml --build-tags ${BUILDTAGS} ${BUILDPATHS}

.PHONY: fmt lint-and-fix
lint-and-fix:
golangci-lint run --new --fix -c .golangci.yaml ${BUILDPATHS}
.PHONY: lint-and-fix
lint-and-fix: fmt vet
golangci-lint run --new --fix -c .golangci.yaml --build-tags ${BUILDTAGS} ${BUILDPATHS}

.PHONY: install-golangci-lint
install-golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}

.PHONY: watch
watch: npm-install
Expand Down
21 changes: 21 additions & 0 deletions cmd/collect/cli/chroot_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cli

import (
"errors"
"syscall"

"github.com/replicatedhq/troubleshoot/internal/util"
)

func checkAndSetChroot(newroot string) error {
if newroot == "" {
return nil
}
if !util.IsRunningAsRoot() {
return errors.New("Can only chroot when run as root")
}
if err := syscall.Chroot(newroot); err != nil {
return err
}
return nil
}
21 changes: 21 additions & 0 deletions cmd/collect/cli/chroot_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cli

import (
"errors"
"syscall"

"github.com/replicatedhq/troubleshoot/internal/util"
)

func checkAndSetChroot(newroot string) error {
if newroot == "" {
return nil
}
if !util.IsRunningAsRoot() {
return errors.New("Can only chroot when run as root")
}
if err := syscall.Chroot(newroot); err != nil {
return err
}
return nil
}
9 changes: 9 additions & 0 deletions cmd/collect/cli/chroot_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package cli

import (
"errors"
)

func checkAndSetChroot(newroot string) error {
return errors.New("chroot is only implimented in linux/darwin")
}
5 changes: 5 additions & 0 deletions cmd/collect/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func RootCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()

if err := checkAndSetChroot(v.GetString("chroot")); err != nil {
return err
}

return runCollect(v, args[0])
},
PostRun: func(cmd *cobra.Command, args []string) {
Expand All @@ -53,6 +57,7 @@ func RootCmd() *cobra.Command {
cmd.Flags().String("selector", "", "selector (label query) to filter remote collection nodes on.")
cmd.Flags().Bool("collect-without-permissions", false, "always generate a support bundle, even if it some require additional permissions")
cmd.Flags().Bool("debug", false, "enable debug logging")
cmd.Flags().String("chroot", "", "Chroot to path")

// hidden in favor of the `insecure-skip-tls-verify` flag
cmd.Flags().Bool("allow-insecure-connections", false, "when set, do not verify TLS certs when retrieving spec and reporting results")
Expand Down
8 changes: 8 additions & 0 deletions cmd/collect/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
Expand Down Expand Up @@ -49,6 +50,13 @@ func runCollect(v *viper.Viper, arg string) error {
}

collectorContent = spec
} else if arg == "-" {
b, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}

collectorContent = b
} else if _, err = os.Stat(arg); err == nil {
b, err := os.ReadFile(arg)
if err != nil {
Expand Down
Loading

0 comments on commit 5791595

Please sign in to comment.