Skip to content

Commit

Permalink
Merge pull request #83 from kirankt/merge-upstream-20200713-103725
Browse files Browse the repository at this point in the history
Merge upstream 20200713 103725
  • Loading branch information
openshift-merge-robot committed Jul 15, 2020
2 parents 2a7f589 + 7c3a893 commit 6312256
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 87 deletions.
27 changes: 18 additions & 9 deletions Makefile
Expand Up @@ -3,6 +3,9 @@ RUN_NAMESPACE = metal3
GO_TEST_FLAGS = $(VERBOSE)
DEBUG = --debug
SETUP = --no-setup
CODE_DIRS = ./cmd ./pkg ./version
PACKAGES = $(foreach dir,$(CODE_DIRS),$(dir)/...)
COVER_PROFILE = cover.out

# See pkg/version.go for details
GIT_COMMIT="$(shell git rev-parse --verify 'HEAD^{commit}')"
Expand Down Expand Up @@ -31,6 +34,12 @@ help: ## Display this help
.PHONY: test
test: fmt generate lint vet unit ## Run common developer tests

.PHONY: show_packages show_dirs
show_packages:
@echo $(PACKAGES)
show_dirs:
@echo $(CODE_DIRS)

.PHONY: generate
generate: bin/operator-sdk ## Run the operator-sdk code generator
./bin/operator-sdk generate $(VERBOSE) k8s
Expand All @@ -54,16 +63,16 @@ travis: unit-verbose lint

.PHONY: unit
unit: ## Run unit tests
go test $(GO_TEST_FLAGS) ./cmd/... ./pkg/...
go test $(GO_TEST_FLAGS) $(PACKAGES)

.PHONY: unit-cover
unit-cover: ## Run unit tests with code coverage
go test -coverprofile=cover.out $(GO_TEST_FLAGS) ./cmd/... ./pkg/...
go tool cover -func=cover.out
go test -coverprofile=$(COVER_PROFILE) $(GO_TEST_FLAGS) $(PACKAGES)
go tool cover -func=$(COVER_PROFILE)

.PHONY: unit-cover-html
unit-cover-html:
go test -coverprofile=cover.out $(GO_TEST_FLAGS) ./cmd/... ./pkg/...
go test -coverprofile=cover.out $(GO_TEST_FLAGS) $(PACKAGES)
go tool cover -html=cover.out

.PHONY: unit-verbose
Expand All @@ -75,11 +84,11 @@ linters: sec lint generate-check fmt-check vet ## Run all linters

.PHONY: vet
vet: ## Run go vet
go vet ./pkg/... ./cmd/...
go vet $(PACKAGES)

.PHONY: lint
lint: golint-binary ## Run golint
find ./pkg ./cmd -type f -name \*.go |grep -v zz_ | xargs -L1 golint -set_exit_status
find $(CODE_DIRS) -type f -name \*.go |grep -v zz_ | xargs -L1 golint -set_exit_status

.PHONY: generate-check
generate-check:
Expand All @@ -90,8 +99,8 @@ generate-check-local:
IS_CONTAINER=local ./hack/generate.sh

.PHONY: sec
sec: $GOPATH/bin/gosec
gosec -severity medium --confidence medium -quiet ./pkg/... ./cmd/...
sec: $GOPATH/bin/gosec ## Run gosec
gosec -severity medium --confidence medium -quiet $(PACKAGES)

$GOPATH/bin/gosec:
go get -u github.com/securego/gosec/cmd/gosec
Expand All @@ -104,7 +113,7 @@ $GOPATH/bin/golint:

.PHONY: fmt
fmt: ## Run gofmt and write changes to each file
gofmt -l -w ./pkg ./cmd
gofmt -l -w $(CODE_DIRS)

.PHONY: fmt-check
fmt-check: ## Run gofmt and report an error if any changes are made
Expand Down
4 changes: 2 additions & 2 deletions deploy/ironic_ci.env
@@ -1,11 +1,11 @@
HTTP_PORT=6180
PROVISIONING_IP=172.22.0.2
PROVISIONING_CIDR=24
PROVISIONING_INTERFACE=provisioning
PROVISIONING_INTERFACE=ironicendpoint
DHCP_RANGE=172.22.0.10,172.22.0.100
DEPLOY_KERNEL_URL=http://172.22.0.2:6180/images/ironic-python-agent.kernel
DEPLOY_RAMDISK_URL=http://172.22.0.2:6180/images/ironic-python-agent.initramfs
IRONIC_ENDPOINT=http://172.22.0.2:6385/v1/
IRONIC_INSPECTOR_ENDPOINT=http://172.22.0.2:5050/v1/
CACHEURL=http://172.22.0.1/images
IRONIC_FAST_TRACK=false
IRONIC_FAST_TRACK=false
8 changes: 4 additions & 4 deletions docs/BaremetalHost_ProvisioningState.dot
@@ -1,11 +1,11 @@
digraph BaremetalHost {
Created [shape=house]
Created -> Discovered [label="BMC.* == \"\""]
Created -> Unmanaged [label="BMC.* == \"\""]
Created -> Registering [label="BMC.* != \"\""]

Discovered [shape=doublecircle]
Discovered -> Registering [label="BMC.* != \"\""]
Discovered -> Deleting1 [label="!DeletionTimestamp.IsZero()"]
Unmanaged [shape=doublecircle]
Unmanaged -> Registering [label="BMC.* != \"\""]
Unmanaged -> Deleting1 [label="!DeletionTimestamp.IsZero()"]

Deleting1 [shape=point]

Expand Down
Binary file modified docs/BaremetalHost_ProvisioningState.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/api.md
Expand Up @@ -369,5 +369,12 @@ Several conditions must be met in order to initiate provisioning.
host receiving the image.
2. The host must have `online` set to `true` so that the operator will
keep the host powered on.
3. The host must have all of the BMC details.

To initiate deprovisioning, clear the image URL from the host spec.

## Unmanaged Hosts

Hosts created without BMC details will be left in the `unmanaged`
state until the details are provided. Unmanaged hosts cannot be
provisioned and their power state is undefined.
63 changes: 63 additions & 0 deletions docs/testing.md
Expand Up @@ -36,3 +36,66 @@ Run linters test before pushing your commit
```bash
make lint
```

## Using the Hack scripts

The repository contains a ``hack`` directory which has some very useful scripts
for setting up containerized testing environments. It also has Dockerfiles to
allow you to generate images for your own use.

All the scripts accept the ``CONTAINER_RUNTIME`` environment variable with default
of ``podman``. This you can edit to ``docker`` as well.

### Example of running ``golint`` in a Docker container

1. Start by setting the environment variable appropriately

```bash
export CONTAINER_RUNTIME=docker
```

2. From the operator parent dir, you can invoke the hack scripts

```bash
./hack/golint.sh
```

**Note** It's important to be in the operator parent dir because it
contains the ``Makefile`` that is used in running the tests for the
operator. Otherwise, you'll see the following error

```bash
sh: 0: Can't open /go/src/github.com/metal3-io/baremetal-operator/hack/golint.sh
```
3. Upon successful execution, you should see the following output. I already
had all the images available from a previous run, you might see the images
getting downloaded if you're running for the very first time.

```bash
+ IS_CONTAINER=false
+ CONTAINER_RUNTIME=docker
+ [ false != false ]
+ docker run --rm --env IS_CONTAINER=TRUE --volume /home/noor/go/src/github.com/metal3-io/baremetal-operator:/go/src/github.com/metal3-io/baremetal-operator:ro,z\
--entrypoint sh --workdir /go/src/github.com/metal3-io/baremetal-operator\
quay.io/metal3-io/golint:latest /go/src/github.com/metal3-io/baremetal-operator/hack/golint.sh
+ IS_CONTAINER=TRUE
+ CONTAINER_RUNTIME=podman
+ [ TRUE != false ]
+ export XDG_CACHE_HOME=/tmp/.cache
+ make lint
which golint 2>&1 >/dev/null || make OPATH/bin/golint
find ./pkg ./cmd -type f -name \*.go |grep -v zz_ | xargs -L1 golint -set_exit_status
```

## Getting the latest tooling

For testing without the hack scripts, make sure you install the latest
development tools using ``go get``, e-g

```bash
go get golang.org/x/lint/golint
```

This ensures that the linters you have locally and the ones running in the CI
are matched and helps avoid inconsistencies. Happy coding!
10 changes: 7 additions & 3 deletions hack/gofmt.sh
Expand Up @@ -9,8 +9,12 @@ if [ "${IS_CONTAINER}" != "false" ]; then
TOP_DIR="${1:-.}"
export XDG_CACHE_HOME="/tmp/.cache"

if [ -n "$(gofmt -l "${TOP_DIR}/pkg" "${TOP_DIR}/cmd")" ]; then
gofmt -d "${TOP_DIR}"/pkg "${TOP_DIR}"/cmd
cd "${TOP_DIR}"
DIRS=$(make show_dirs)

# shellcheck disable=SC2086
if [ -n "$(gofmt -l ${DIRS})" ]; then
make fmt
exit 1
fi
else
Expand All @@ -19,6 +23,6 @@ else
--volume "${PWD}:/workdir:rw,z" \
--entrypoint sh \
--workdir /workdir \
registry.hub.docker.com/library/golang:1.12 \
registry.hub.docker.com/library/golang:1.13.7 \
/workdir/hack/gofmt.sh "${@}"
fi;
3 changes: 2 additions & 1 deletion hack/gosec.sh
Expand Up @@ -7,7 +7,8 @@ CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"

if [ "${IS_CONTAINER}" != "false" ]; then
export XDG_CACHE_HOME="/tmp/.cache"
gosec -severity medium --confidence medium -quiet ./pkg/... ./cmd/...

gosec -severity medium --confidence medium -quiet ./pkg/... ./cmd/... ./version/...
else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
Expand Down
6 changes: 3 additions & 3 deletions hack/govet.sh
Expand Up @@ -6,15 +6,15 @@ IS_CONTAINER=${IS_CONTAINER:-false}
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"

if [ "${IS_CONTAINER}" != "false" ]; then
TOP_DIR="${1:-.}"
export XDG_CACHE_HOME="/tmp/.cache"
go vet "${TOP_DIR}"/pkg/... "${TOP_DIR}"/cmd/...

make vet
else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/go/src/github.com/metal3-io/baremetal-operator:ro,z" \
--entrypoint sh \
--workdir /go/src/github.com/metal3-io/baremetal-operator \
registry.hub.docker.com/library/golang:1.12 \
registry.hub.docker.com/library/golang:1.13.7 \
/go/src/github.com/metal3-io/baremetal-operator/hack/govet.sh "${@}"
fi;
7 changes: 6 additions & 1 deletion hack/unit.sh
Expand Up @@ -10,7 +10,12 @@ if [ "${IS_CONTAINER}" != "false" ]; then
eval "$(go env)"
cd "${GOPATH}"/src/github.com/metal3-io/baremetal-operator
export XDG_CACHE_HOME="/tmp/.cache"
go test -v ./pkg/... ./cmd/... -coverprofile "${ARTIFACTS}"/cover.out

export VERBOSE=-v
export COVER_PROFILE="${ARTIFACTS}"/cover.out

make -e unit-cover

else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/metal3/v1alpha1/baremetalhost_types.go
Expand Up @@ -638,6 +638,11 @@ func (host *BareMetalHost) getLabel(name string) string {
return host.Labels[name]
}

// HasBMCDetails returns true if the BMC details are set
func (host *BareMetalHost) HasBMCDetails() bool {
return host.Spec.BMC.Address != "" || host.Spec.BMC.CredentialsName != ""
}

// NeedsHardwareProfile returns true if the profile is not set
func (host *BareMetalHost) NeedsHardwareProfile() bool {
return host.Status.HardwareProfile == ""
Expand Down

0 comments on commit 6312256

Please sign in to comment.