sigs.k8s.io/gateway-api@v1.0.0/Makefile (about)

     1  # Copyright 2019 The Kubernetes Authors.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # We need all the Make variables exported as env vars.
    16  # Note that the ?= operator works regardless.
    17  
    18  # Enable Go modules.
    19  export GO111MODULE=on
    20  
    21  # The registry to push container images to.
    22  export REGISTRY ?= gcr.io/k8s-staging-gateway-api
    23  
    24  # These are overridden by cloudbuild.yaml when run by Prow.
    25  
    26  # Prow gives this a value of the form vYYYYMMDD-hash.
    27  # (It's similar to `git describe` output, and for non-tag
    28  # builds will give vYYYYMMDD-COMMITS-HASH where COMMITS is the
    29  # number of commits since the last tag.)
    30  export GIT_TAG ?= dev
    31  
    32  # Prow gives this the reference it's called on.
    33  # The test-infra config job only allows our cloudbuild to
    34  # be called on `main` and semver tags, so this will be
    35  # set to one of those things.
    36  export BASE_REF ?= main
    37  
    38  # The commit hash of the current checkout
    39  # Used to pass a binary version for main,
    40  # overridden to semver for tagged versions.
    41  # Cloudbuild will set this in the environment to the
    42  # commit SHA, since the Prow does not seem to check out
    43  # a git repo.
    44  export COMMIT ?= $(shell git rev-parse --short HEAD)
    45  
    46  DOCKER ?= docker
    47  # TOP is the current directory where this Makefile lives.
    48  TOP := $(dir $(firstword $(MAKEFILE_LIST)))
    49  # ROOT is the root of the mkdocs tree.
    50  ROOT := $(abspath $(TOP))
    51  
    52  # Command-line flags passed to "go test" for the conformance
    53  # test. These are passed after the "-args" flag.
    54  CONFORMANCE_FLAGS ?=
    55  GO_TEST_FLAGS ?=
    56  
    57  all: generate vet fmt verify test
    58  
    59  # Run generators for protos, Deepcopy funcs, CRDs, and docs.
    60  .PHONY: generate
    61  generate: update-codegen update-webhook-yaml
    62  
    63  .PHONY: update-codegen
    64  update-codegen:
    65  	hack/update-codegen.sh
    66  
    67  .PHONY: update-webhook-yaml
    68  update-webhook-yaml:
    69  	hack/update-webhook-yaml.sh
    70  
    71  .PHONY: build-install-yaml
    72  build-install-yaml:
    73  	hack/build-install-yaml.sh
    74  
    75  # Run go fmt against code
    76  fmt:
    77  	go fmt ./...
    78  
    79  # Run go vet against code
    80  vet:
    81  	go vet ./...
    82  
    83  # Run go test against code
    84  test:
    85  	go test -race -cover ./pkg/admission/... ./apis/... ./conformance/utils/...
    86  # Run tests for each submodule.
    87  	cd "conformance/echo-basic" && go test -race -cover ./...
    88  	cd "gwctl" && go test -race -cover ./...
    89  
    90  # Run conformance tests against controller implementation
    91  .PHONY: conformance
    92  conformance:
    93  	go test ${GO_TEST_FLAGS} -v ./conformance -run TestConformance -args ${CONFORMANCE_FLAGS}
    94  
    95  # Run experimental conformance tests against controller implementation
    96  .PHONY: conformance.experimental
    97  conformance.experimental:
    98  	go test ${GO_TEST_FLAGS} -v ./conformance -run TestExperimentalConformance -args ${CONFORMANCE_FLAGS}
    99  
   100  # Install CRD's and example resources to a pre-existing cluster.
   101  .PHONY: install
   102  install: crd example
   103  
   104  # Install the CRD's to a pre-existing cluster.
   105  .PHONY: crd
   106  crd:
   107  	kubectl kustomize config/crd | kubectl apply -f -
   108  
   109  # Install the example resources to a pre-existing cluster.
   110  .PHONY: example
   111  example:
   112  	hack/install-examples.sh
   113  
   114  # Remove installed CRD's and CR's.
   115  .PHONY: uninstall
   116  uninstall:
   117  	hack/delete-crds.sh
   118  
   119  # Run static analysis.
   120  .PHONY: verify
   121  verify:
   122  	hack/verify-all.sh -v
   123  
   124  # Build the documentation.
   125  .PHONY: docs
   126  docs:
   127  	hack/make-docs.sh
   128  
   129  .PHONY: update-conformance-image-refs
   130  update-conformance-image-refs:
   131  	hack/update-conformance-image-refs.sh
   132  
   133  # Verify if support Docker Buildx.
   134  .PHONY: image.buildx.verify
   135  image.buildx.verify:
   136  	docker version
   137  	$(eval PASS := $(shell docker buildx --help | grep "docker buildx" ))
   138  	@if [ -z "$(PASS)" ]; then \
   139  		echo "Cannot find docker buildx, please install first."; \
   140  		exit 1;\
   141  	else \
   142  		echo "===========> Support docker buildx"; \
   143  		docker buildx version; \
   144  	fi
   145  
   146  export BUILDX_CONTEXT = gateway-api-builder
   147  export BUILDX_PLATFORMS = linux/amd64,linux/arm64
   148  
   149  # Setup multi-arch docker buildx environment.
   150  .PHONY: image.multiarch.setup
   151  image.multiarch.setup: image.buildx.verify
   152  # Ensure qemu is in binfmt_misc.
   153  # Docker desktop already has these in versions recent enough to have buildx,
   154  # We only need to do this setup on linux hosts.
   155  	@if [ "$(shell uname)" == "Linux" ]; then \
   156  		docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; \
   157  	fi
   158  # Ensure we use a builder that can leverage it, we need to recreate one.
   159  	docker buildx rm $(BUILDX_CONTEXT) || :
   160  	docker buildx create --use --name $(BUILDX_CONTEXT) --platform "${BUILDX_PLATFORMS}"
   161  
   162  # Build and Push Multi Arch Images.
   163  .PHONY: release-staging
   164  release-staging: image.multiarch.setup
   165  	hack/build-and-push.sh
   166  
   167  # Generate a virtualenv install, which is useful for hacking on the
   168  # docs since it installs mkdocs and all the right dependencies.
   169  #
   170  # On Ubuntu, this requires the python3-venv package.
   171  virtualenv: .venv
   172  .venv: requirements.txt
   173  	@echo Creating a virtualenv in $@"... "
   174  	@python3 -m venv $@ || (rm -rf $@ && exit 1)
   175  	@echo Installing packages in $@"... "
   176  	@$@/bin/python3 -m pip install -q -r requirements.txt || (rm -rf $@ && exit 1)
   177  	@echo To enter the virtualenv type \"source $@/bin/activate\",  to exit type \"deactivate\"