mirror of https://github.com/kubernetes/kops.git
Use build tags for Protokube
This commit is contained in:
parent
9dd9c61514
commit
ed4bf6d880
9
Makefile
9
Makefile
|
@ -213,7 +213,7 @@ crossbuild-nodeup: nodeup-amd64 nodeup-arm64
|
||||||
.PHONY: protokube-amd64 protokube-arm64
|
.PHONY: protokube-amd64 protokube-arm64
|
||||||
protokube-amd64 protokube-arm64: protokube-%:
|
protokube-amd64 protokube-arm64: protokube-%:
|
||||||
mkdir -p ${DIST}/linux/$*
|
mkdir -p ${DIST}/linux/$*
|
||||||
GOOS=linux GOARCH=$* go build ${GCFLAGS} ${BUILDFLAGS} ${EXTRA_BUILDFLAGS} -o ${DIST}/linux/$*/protokube ${LDFLAGS}"${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/protokube/cmd/protokube
|
GOOS=linux GOARCH=$* go build -tags=peer_name_alternative,peer_name_hash ${GCFLAGS} ${BUILDFLAGS} ${EXTRA_BUILDFLAGS} -o ${DIST}/linux/$*/protokube ${LDFLAGS}"${EXTRA_LDFLAGS} -X k8s.io/kops.Version=${VERSION} -X k8s.io/kops.GitVersion=${GITSHA}" k8s.io/kops/protokube/cmd/protokube
|
||||||
|
|
||||||
.PHONY: protokube
|
.PHONY: protokube
|
||||||
protokube: protokube-amd64
|
protokube: protokube-amd64
|
||||||
|
@ -296,7 +296,7 @@ dns-controller-push: ko-dns-controller-push
|
||||||
|
|
||||||
.PHONY: ko-dns-controller-push
|
.PHONY: ko-dns-controller-push
|
||||||
ko-dns-controller-push: ko
|
ko-dns-controller-push: ko
|
||||||
KO_DOCKER_REPO="${DOCKER_REGISTRY}/${DOCKER_IMAGE_PREFIX}dns-controller" ko build --tags ${DNS_CONTROLLER_PUSH_TAG} --platform=linux/amd64,linux/arm64 --bare ./dns-controller/cmd/dns-controller/
|
KO_DOCKER_REPO="${DOCKER_REGISTRY}/${DOCKER_IMAGE_PREFIX}dns-controller" GOFLAGS="-tags=peer_name_alternative,peer_name_hash" ko build --tags ${DNS_CONTROLLER_PUSH_TAG} --platform=linux/amd64,linux/arm64 --bare ./dns-controller/cmd/dns-controller/
|
||||||
|
|
||||||
# --------------------------------------------------
|
# --------------------------------------------------
|
||||||
# development targets
|
# development targets
|
||||||
|
@ -305,9 +305,6 @@ ko-dns-controller-push: ko
|
||||||
gomod:
|
gomod:
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod vendor
|
go mod vendor
|
||||||
# Switch weavemesh to use peer_name_hash - bazel rule-go doesn't support build tags yet
|
|
||||||
rm vendor/github.com/weaveworks/mesh/peer_name_mac.go
|
|
||||||
sed -i.bak -e 's/peer_name_hash/!peer_name_mac/g' vendor/github.com/weaveworks/mesh/peer_name_hash.go
|
|
||||||
cd tests/e2e; go mod tidy
|
cd tests/e2e; go mod tidy
|
||||||
cd hack; go mod tidy
|
cd hack; go mod tidy
|
||||||
|
|
||||||
|
@ -531,7 +528,7 @@ ko-kube-apiserver-healthcheck-export: ko-kube-apiserver-healthcheck-export-linux
|
||||||
.PHONY: ko-dns-controller-export-linux-amd64 ko-dns-controller-export-linux-arm64
|
.PHONY: ko-dns-controller-export-linux-amd64 ko-dns-controller-export-linux-arm64
|
||||||
ko-dns-controller-export-linux-amd64 ko-dns-controller-export-linux-arm64: ko-dns-controller-export-linux-%: ko
|
ko-dns-controller-export-linux-amd64 ko-dns-controller-export-linux-arm64: ko-dns-controller-export-linux-%: ko
|
||||||
mkdir -p ${IMAGES}
|
mkdir -p ${IMAGES}
|
||||||
KO_DOCKER_REPO="registry.k8s.io/kops" ko build --tags ${DNS_CONTROLLER_TAG} --platform=linux/$* -B --push=false --tarball=${IMAGES}/dns-controller-$*.tar ./dns-controller/cmd/dns-controller
|
KO_DOCKER_REPO="registry.k8s.io/kops" GOFLAGS="-tags=peer_name_alternative,peer_name_hash" ko build --tags ${DNS_CONTROLLER_TAG} --platform=linux/$* -B --push=false --tarball=${IMAGES}/dns-controller-$*.tar ./dns-controller/cmd/dns-controller
|
||||||
gzip -f ${IMAGES}/dns-controller-$*.tar
|
gzip -f ${IMAGES}/dns-controller-$*.tar
|
||||||
tools/sha256 ${IMAGES}/dns-controller-$*.tar.gz ${IMAGES}/dns-controller-$*.tar.gz.sha256
|
tools/sha256 ${IMAGES}/dns-controller-$*.tar.gz ${IMAGES}/dns-controller-$*.tar.gz.sha256
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !peer_name_mac
|
// +build peer_name_hash
|
||||||
|
|
||||||
package mesh
|
package mesh
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
// +build peer_name_mac !peer_name_alternative
|
||||||
|
|
||||||
|
package mesh
|
||||||
|
|
||||||
|
// The !peer_name_alternative effectively makes this the default,
|
||||||
|
// i.e. to choose an alternative, run
|
||||||
|
//
|
||||||
|
// go build -tags 'peer_name_alternative peer_name_hash'
|
||||||
|
//
|
||||||
|
// Let peer names be MACs...
|
||||||
|
//
|
||||||
|
// MACs need to be unique across our network, or bad things will
|
||||||
|
// happen anyway. So they make pretty good candidates for peer
|
||||||
|
// names. And doing so is pretty efficient both computationally and
|
||||||
|
// network overhead wise.
|
||||||
|
//
|
||||||
|
// Note that we do not mandate *what* MAC should be used as the peer
|
||||||
|
// name. In particular it doesn't actually have to be the MAC of, say,
|
||||||
|
// the network interface the peer is sniffing on.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PeerName is used as a map key. Since net.HardwareAddr isn't suitable for
|
||||||
|
// that - it's a slice, and slices can't be map keys - we convert that to/from
|
||||||
|
// uint64.
|
||||||
|
type PeerName uint64
|
||||||
|
|
||||||
|
const (
|
||||||
|
// PeerNameFlavour is the type of peer names we use.
|
||||||
|
PeerNameFlavour = "mac"
|
||||||
|
|
||||||
|
// NameSize is the number of bytes in a peer name.
|
||||||
|
NameSize = 6
|
||||||
|
|
||||||
|
// UnknownPeerName is used as a sentinel value.
|
||||||
|
UnknownPeerName = PeerName(0)
|
||||||
|
)
|
||||||
|
|
||||||
|
// PeerNameFromUserInput parses PeerName from a user-provided string.
|
||||||
|
func PeerNameFromUserInput(userInput string) (PeerName, error) {
|
||||||
|
return PeerNameFromString(userInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PeerNameFromString parses PeerName from a generic string.
|
||||||
|
func PeerNameFromString(nameStr string) (PeerName, error) {
|
||||||
|
var a, b, c, d, e, f uint64
|
||||||
|
|
||||||
|
match := func(format string, args ...interface{}) bool {
|
||||||
|
a, b, c, d, e, f = 0, 0, 0, 0, 0, 0
|
||||||
|
n, err := fmt.Sscanf(nameStr+"\000", format+"\000", args...)
|
||||||
|
return err == nil && n == len(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case match("%2x:%2x:%2x:%2x:%2x:%2x", &a, &b, &c, &d, &e, &f):
|
||||||
|
case match("::%2x:%2x:%2x:%2x", &c, &d, &e, &f):
|
||||||
|
case match("%2x::%2x:%2x:%2x", &a, &d, &e, &f):
|
||||||
|
case match("%2x:%2x::%2x:%2x", &a, &b, &e, &f):
|
||||||
|
case match("%2x:%2x:%2x::%2x", &a, &b, &c, &f):
|
||||||
|
case match("%2x:%2x:%2x:%2x::", &a, &b, &c, &d):
|
||||||
|
case match("::%2x:%2x:%2x", &d, &e, &f):
|
||||||
|
case match("%2x::%2x:%2x", &a, &e, &f):
|
||||||
|
case match("%2x:%2x::%2x", &a, &b, &f):
|
||||||
|
case match("%2x:%2x:%2x::", &a, &b, &c):
|
||||||
|
case match("::%2x:%2x", &e, &f):
|
||||||
|
case match("%2x::%2x", &a, &f):
|
||||||
|
case match("%2x:%2x::", &a, &b):
|
||||||
|
case match("::%2x", &f):
|
||||||
|
case match("%2x::", &a):
|
||||||
|
default:
|
||||||
|
return UnknownPeerName, fmt.Errorf("invalid peer name format: %q", nameStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return PeerName(a<<40 | b<<32 | c<<24 | d<<16 | e<<8 | f), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PeerNameFromBin parses PeerName from a byte slice.
|
||||||
|
func PeerNameFromBin(nameByte []byte) PeerName {
|
||||||
|
return PeerName(macint(net.HardwareAddr(nameByte)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// bytes encodes PeerName as a byte slice.
|
||||||
|
func (name PeerName) bytes() []byte {
|
||||||
|
return intmac(uint64(name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// String encodes PeerName as a string.
|
||||||
|
func (name PeerName) String() string {
|
||||||
|
return intmac(uint64(name)).String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func macint(mac net.HardwareAddr) (r uint64) {
|
||||||
|
for _, b := range mac {
|
||||||
|
r <<= 8
|
||||||
|
r |= uint64(b)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func intmac(key uint64) (r net.HardwareAddr) {
|
||||||
|
r = make([]byte, 6)
|
||||||
|
for i := 5; i >= 0; i-- {
|
||||||
|
r[i] = byte(key)
|
||||||
|
key >>= 8
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in New Issue