Skip to content

Commit

Permalink
chore: minor updates to docs and Makefile
Browse files Browse the repository at this point in the history
* Deprecate old Makefile targets
* Name Makefile targets to point to files they 'make' as per convention
* Update the contributing doc
* Update CLI docs left behind
  • Loading branch information
banjoh committed Jan 25, 2024
1 parent 80de5e3 commit 75d8e52
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 51 deletions.
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ linters:
- gocyclo
- gofmt
- gosec
- govet
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ To get started we recommend:

1. Go (v1.20 or later)
2. A Kubernetes cluster (we recommend <https://k3d.io/>. This requires Docker v20.10.5 or later)
3. Fork and clone the repo to $GOPATH/src/github.com/replicatedhq/
4. Run `make support-bundle preflight` to generate binaries
5. Run `make run-troubleshoot` to generate a support bundle with the `sample-troubleshoot.yaml` in the root of the repo
3. Fork and clone repo
4. Run `make clean build` to generate binaries
5. Run `make run-support-bundle` to generate a support bundle with the `sample-troubleshoot.yaml` in the root of the repo

> Note: recent versions of Go support easy cross-compilation. For example, to cross-compile a Linux binary from MacOS:
> `GOOS=linux GOARCH=amd64 make support-bundle preflight`
> `GOOS=linux GOARCH=amd64 make clean build`
6. Install [golangci-lint] linter and run `make lint` to execute additional code linters.

Expand Down
106 changes: 68 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ BUILDPATHS = ./pkg/... ./cmd/... ./internal/...
E2EPATHS = ./test/e2e/...
TESTFLAGS ?= -v -coverprofile cover.out

.DEFAULT: all
all: test build
.DEFAULT_GOAL := all
all: build test

.PHONY: ffi
ffi: fmt vet
Expand Down Expand Up @@ -81,27 +81,35 @@ support-bundle-e2e-go-test:
fi

# Build all binaries in parallel ( -j )
build:
build: tidy
@echo "Build cli binaries"
$(MAKE) -j support-bundle preflight analyze collect

mod-tidy:
$(MAKE) -j bin/support-bundle bin/preflight bin/analyze bin/collect

.PHONY: clean
clean:
@rm -f bin/analyze
@rm -f bin/support-bundle
@rm -f bin/collect
@rm -f bin/preflight
@rm -f bin/troubleshoot.h
@rm -f bin/troubleshoot.so
@rm -f bin/schemagen
@rm -f bin/docsgen

.PHONY: tidy
tidy:
go mod tidy

.PHONY: support-bundle
support-bundle:
bin/support-bundle:
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot

.PHONY: preflight
preflight:
bin/preflight:
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight

.PHONY: analyze
analyze:
bin/analyze:
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze

.PHONY: collect
collect:
bin/collect:
go build ${BUILDFLAGS} ${LDFLAGS} -o bin/collect github.com/replicatedhq/troubleshoot/cmd/collect

.PHONY: fmt
Expand Down Expand Up @@ -138,15 +146,19 @@ check-schemas: generate schemas
fi

.PHONY: schemas
schemas: fmt vet openapischema
go build ${LDFLAGS} -o bin/schemagen github.com/replicatedhq/troubleshoot/cmd/schemagen
schemas: fmt vet openapischema bin/schemagen
./bin/schemagen --output-dir ./schemas

bin/schemagen:
go build ${LDFLAGS} -o bin/schemagen github.com/replicatedhq/troubleshoot/cmd/schemagen

.PHONY: docs
docs: fmt vet
go build ${LDFLAGS} -o bin/docsgen github.com/replicatedhq/troubleshoot/cmd/docsgen
docs: fmt vet bin/docsgen
./bin/docsgen

bin/docsgen:
go build ${LDFLAGS} -o bin/docsgen github.com/replicatedhq/troubleshoot/cmd/docsgen

controller-gen:
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.11.2
CONTROLLER_GEN=$(shell which controller-gen)
Expand Down Expand Up @@ -180,15 +192,15 @@ local-release:
docker push localhost:32000/preflight:alpha

.PHONY: run-preflight
run-preflight: preflight
run-preflight: bin/preflight
./bin/preflight ./examples/preflight/sample-preflight.yaml

.PHONY: run-troubleshoot
run-troubleshoot: support-bundle
.PHONY: run-support-bundle
run-support-bundle: bin/support-bundle
./bin/support-bundle ./examples/support-bundle/sample-supportbundle.yaml

.PHONY: run-analyze
run-analyze: analyze
run-analyze: bin/analyze
./bin/analyze --analyzers ./examples/support-bundle/sample-analyzers.yaml ./support-bundle.tar.gz

.PHONY: init-sbom
Expand All @@ -212,20 +224,6 @@ sbom: sbom/assets/troubleshoot-sbom.tgz
cosign sign-blob -key cosign.key sbom/assets/troubleshoot-sbom.tgz > sbom/assets/troubleshoot-sbom.tgz.sig
cosign public-key -key cosign.key -outfile sbom/assets/key.pub

longhorn:
git clone https://github.com/longhorn/longhorn-manager.git
cd longhorn-manager && git checkout v1.2.2 && cd ..
rm -rf pkg/longhorn
mv longhorn-manager/k8s/pkg pkg/longhorn
mv longhorn-manager/types pkg/longhorn/types
mv longhorn-manager/util pkg/longhorn/util
rm -rf pkg/longhorn/util/daemon
rm -rf pkg/longhorn/util/server
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/k8s\/pkg/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn/g"
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/types/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn\/types/g"
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/util/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn\/util/g"
rm -rf longhorn-manager

.PHONY: scan
scan:
trivy fs \
Expand All @@ -236,11 +234,11 @@ scan:
./

.PHONY: lint
lint: fmt vet
lint:
golangci-lint run --new -c .golangci.yaml ${BUILDPATHS}

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

.PHONY: watch
Expand All @@ -256,3 +254,35 @@ watchrsync: npm-install
npm-install:
npm --version 2>&1 >/dev/null || ( echo "npm not installed; install npm to set up watchrsync" && exit 1 )
npm list gaze-run-interrupt || npm install install --no-save gaze-run-interrupt@~2.0.0


######## Lagacy make targets ###########
# Deprecated: These can be removed
.PHONY: support-bundle
support-bundle: clean bin/support-bundle

.PHONY: preflight
preflight: clean bin/preflight

.PHONY: analyze
analyze: clean bin/analyze

.PHONY: collect
collect: clean bin/collect

.PHONY: run-troubleshoot
run-troubleshoot: run-support-bundle

longhorn:
git clone https://github.com/longhorn/longhorn-manager.git
cd longhorn-manager && git checkout v1.2.2 && cd ..
rm -rf pkg/longhorn
mv longhorn-manager/k8s/pkg pkg/longhorn
mv longhorn-manager/types pkg/longhorn/types
mv longhorn-manager/util pkg/longhorn/util
rm -rf pkg/longhorn/util/daemon
rm -rf pkg/longhorn/util/server
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/k8s\/pkg/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn/g"
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/types/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn\/types/g"
find pkg/longhorn -type f | xargs sed -i "s/github.com\/longhorn\/longhorn-manager\/util/github.com\/replicatedhq\/troubleshoot\/pkg\/longhorn\/util/g"
rm -rf longhorn-manager
2 changes: 1 addition & 1 deletion docs/preflight.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ preflight [url] [flags]
* [preflight oci-fetch](preflight_oci-fetch.md) - Fetch a preflight from an OCI registry and print it to standard out
* [preflight version](preflight_version.md) - Print the current version and exit

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024
5 changes: 3 additions & 2 deletions docs/preflight_oci-fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ preflight oci-fetch [URI] [flags]
### Options

```
-h, --help help for oci-fetch
-h, --help help for oci-fetch
-v, --v Level number for the log level verbosity
```

### Options inherited from parent commands
Expand All @@ -33,4 +34,4 @@ preflight oci-fetch [URI] [flags]

* [preflight](preflight.md) - Run and retrieve preflight checks in a cluster

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024
2 changes: 1 addition & 1 deletion docs/preflight_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ preflight version [flags]

* [preflight](preflight.md) - Run and retrieve preflight checks in a cluster

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024
5 changes: 3 additions & 2 deletions docs/support-bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ support-bundle [urls...] [flags]
--cpuprofile string File path to write cpu profiling data
--debug enable debug logging. This is equivalent to --v=0
--disable-compression If true, opt-out of response compression for all requests to the server
--dry-run print support bundle spec without collecting anything
-h, --help help for support-bundle
--insecure-skip-tls-verify If true, the server's certificate will not be checked for validity. This will make your HTTPS connections insecure
--interactive enable/disable interactive mode (default true)
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
--load-cluster-specs enable/disable loading additional troubleshoot specs found within the cluster. required when no specs are provided on the command line
--memprofile string File path to write memory profiling data
-n, --namespace string If present, the namespace scope for this CLI request
--no-uri When this flag is used, Troubleshoot does not attempt to retrieve the bundle referenced by the uri: field in the spec.`
--no-uri When this flag is used, Troubleshoot does not attempt to retrieve the spec referenced by the uri: field`
-o, --output string specify the output file path for the support bundle
--redact enable/disable default redactions (default true)
--redactors strings names of the additional redactors to use
Expand All @@ -55,4 +56,4 @@ support-bundle [urls...] [flags]
* [support-bundle redact](support-bundle_redact.md) - Redact information from a generated support bundle archive
* [support-bundle version](support-bundle_version.md) - Print the current version and exit

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024
2 changes: 1 addition & 1 deletion docs/support-bundle_analyze.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ support-bundle analyze [url] [flags]

* [support-bundle](support-bundle.md) - Generate a support bundle

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024
2 changes: 1 addition & 1 deletion docs/support-bundle_redact.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ support-bundle redact [urls...] [flags]

* [support-bundle](support-bundle.md) - Generate a support bundle

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024
2 changes: 1 addition & 1 deletion docs/support-bundle_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ support-bundle version [flags]

* [support-bundle](support-bundle.md) - Generate a support bundle

###### Auto generated by spf13/cobra on 31-Aug-2023
###### Auto generated by spf13/cobra on 25-Jan-2024

0 comments on commit 75d8e52

Please sign in to comment.