mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-28 10:47:23 +00:00
Merge pull request #829 from marquiz/devel/generate-containerized
Containerized auto-generation
This commit is contained in:
commit
b78f65e9ee
35 changed files with 156 additions and 53 deletions
22
Dockerfile_generator
Normal file
22
Dockerfile_generator
Normal file
|
@ -0,0 +1,22 @@
|
|||
FROM golang:1.18-buster as builder
|
||||
|
||||
# Install tools
|
||||
RUN go install github.com/vektra/mockery/v2@v2.13.0 && \
|
||||
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0 && \
|
||||
git clone https://github.com/kubernetes/code-generator -b v0.20.7 --depth 1 && \
|
||||
go install k8s.io/code-generator/cmd/...@v0.20.7 && \
|
||||
go install golang.org/x/tools/cmd/goimports@v0.1.1 && \
|
||||
go install github.com/golang/protobuf/protoc-gen-go@v1.4.3
|
||||
|
||||
RUN apt-get update && apt-get install unzip
|
||||
|
||||
RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protoc-3.17.3-linux-x86_64.zip && \
|
||||
unzip protoc-3.17.3-linux-x86_64.zip -d /usr/local && \
|
||||
rm protoc-3.17.3-linux-x86_64.zip && \
|
||||
chmod a+x /usr/local/bin/protoc && \
|
||||
find /usr/local -type d | xargs chmod 755 && \
|
||||
find /usr/local -type f | xargs chmod a+r
|
||||
|
||||
|
||||
# Expect to be working with nfd
|
||||
WORKDIR /go/node-feature-discovery
|
28
Makefile
28
Makefile
|
@ -14,8 +14,6 @@ BASE_IMAGE_MINIMAL ?= gcr.io/distroless/base
|
|||
|
||||
MDL ?= mdl
|
||||
|
||||
K8S_CODE_GENERATOR ?= ../code-generator
|
||||
|
||||
# Docker base command for working with html documentation.
|
||||
# Use host networking because 'jekyll serve' is stupid enough to use the
|
||||
# same site url than the "host" it binds to. Thus, all the links will be
|
||||
|
@ -129,21 +127,17 @@ templates:
|
|||
-e "}; /$$end/p; d }" -i deployment/helm/node-feature-discovery/values.yaml
|
||||
@rm nfd-worker.conf.tmp
|
||||
|
||||
generate:
|
||||
go mod vendor
|
||||
go generate ./cmd/... ./pkg/... ./source/...
|
||||
rm -rf vendor/
|
||||
controller-gen object crd output:crd:stdout paths=./pkg/apis/... > deployment/base/nfd-crds/nodefeaturerule-crd.yaml
|
||||
cp deployment/base/nfd-crds/nodefeaturerule-crd.yaml deployment/helm/node-feature-discovery/manifests/
|
||||
rm -rf sigs.k8s.io
|
||||
$(K8S_CODE_GENERATOR)/generate-groups.sh client,informer,lister \
|
||||
sigs.k8s.io/node-feature-discovery/pkg/generated \
|
||||
sigs.k8s.io/node-feature-discovery/pkg/apis \
|
||||
"nfd:v1alpha1" --output-base=. \
|
||||
--go-header-file hack/boilerplate.go.txt
|
||||
rm -rf pkg/generated
|
||||
mv sigs.k8s.io/node-feature-discovery/pkg/generated pkg/
|
||||
rm -rf sigs.k8s.io
|
||||
.generator.image.stamp: Dockerfile_generator
|
||||
$(IMAGE_BUILD_CMD) -t nfd-generator -f Dockerfile_generator .
|
||||
|
||||
generate: .generator.image.stamp
|
||||
$(CONTAINER_RUN_CMD) --rm \
|
||||
-v "`pwd`:/go/node-feature-discovery" \
|
||||
-v "`go env GOCACHE`:/.cache" \
|
||||
-v "`go env GOMODCACHE`:/go/pkg/mod" \
|
||||
--user=`id -u`:`id -g`\
|
||||
nfd-generator \
|
||||
./hack/generate.sh
|
||||
|
||||
gofmt:
|
||||
@$(GO_FMT) -w -l $$(find . -name '*.go')
|
||||
|
|
30
hack/generate.sh
Executable file
30
hack/generate.sh
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash -e
|
||||
set -o pipefail
|
||||
|
||||
# Default path for code-generator repo
|
||||
K8S_CODE_GENERATOR=${K8S_CODE_GENERATOR:-../code-generator}
|
||||
|
||||
go mod vendor
|
||||
|
||||
go generate ./cmd/... ./pkg/... ./source/...
|
||||
|
||||
rm -rf vendor/
|
||||
|
||||
controller-gen object crd output:crd:stdout paths=./pkg/apis/... > deployment/base/nfd-crds/nodefeaturerule-crd.yaml
|
||||
|
||||
cp deployment/base/nfd-crds/nodefeaturerule-crd.yaml deployment/helm/node-feature-discovery/manifests/
|
||||
|
||||
rm -rf sigs.k8s.io
|
||||
|
||||
${K8S_CODE_GENERATOR}/generate-groups.sh client,informer,lister \
|
||||
sigs.k8s.io/node-feature-discovery/pkg/generated \
|
||||
sigs.k8s.io/node-feature-discovery/pkg/apis \
|
||||
"nfd:v1alpha1" --output-base=. \
|
||||
--go-header-file hack/boilerplate.go.txt
|
||||
|
||||
rm -rf pkg/generated
|
||||
|
||||
mv sigs.k8s.io/node-feature-discovery/pkg/generated pkg/
|
||||
|
||||
rm -rf sigs.k8s.io
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
package apihelper
|
||||
|
||||
//go:generate mockery --name=APIHelpers --inpkg
|
||||
//go:generate mockery --name=APIHelpers --inpackage
|
||||
|
||||
import (
|
||||
topologyclientset "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/clientset/versioned"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.13.0. DO NOT EDIT.
|
||||
|
||||
package apihelper
|
||||
|
||||
|
@ -172,3 +172,18 @@ func (_m *MockAPIHelpers) UpdateNode(_a0 *kubernetes.Clientset, _a1 *v1.Node) er
|
|||
|
||||
return r0
|
||||
}
|
||||
|
||||
type NewMockAPIHelpersT interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockAPIHelpers creates a new instance of MockAPIHelpers. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockAPIHelpers(t NewMockAPIHelpersT) *MockAPIHelpers {
|
||||
mock := &MockAPIHelpers{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
@ -74,10 +74,7 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
|
|||
return c.tracker
|
||||
}
|
||||
|
||||
var (
|
||||
_ clientset.Interface = &Clientset{}
|
||||
_ testing.FakeClient = &Clientset{}
|
||||
)
|
||||
var _ clientset.Interface = &Clientset{}
|
||||
|
||||
// NfdV1alpha1 retrieves the NfdV1alpha1Client
|
||||
func (c *Clientset) NfdV1alpha1() nfdv1alpha1.NfdV1alpha1Interface {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright 2021 The Kubernetes Authors.
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -17,4 +17,4 @@ limitations under the License.
|
|||
package labeler
|
||||
|
||||
//go:generate protoc --go_opt=paths=source_relative --go_out=plugins=grpc:. -I . -I ../.. -I ../../vendor labeler.proto
|
||||
//go:generate mockery --name=LabelerClient --inpkg
|
||||
//go:generate mockery --name=LabelerClient --inpackage
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.13.0. DO NOT EDIT.
|
||||
|
||||
package labeler
|
||||
|
||||
|
@ -44,3 +44,18 @@ func (_m *MockLabelerClient) SetLabels(ctx context.Context, in *SetLabelsRequest
|
|||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
type NewMockLabelerClientT interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockLabelerClient creates a new instance of MockLabelerClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockLabelerClient(t NewMockLabelerClientT) *MockLabelerClient {
|
||||
mock := &MockLabelerClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
|
|
|
@ -17,4 +17,4 @@ limitations under the License.
|
|||
package topologyupdater
|
||||
|
||||
//go:generate protoc --go_opt=paths=source_relative --go_out=plugins=grpc:. -I . -I ../../vendor/ topology-updater.proto
|
||||
//go:generate mockery --name=NodeTopologyClient --inpkg
|
||||
//go:generate mockery --name=NodeTopologyClient --inpackage
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.13.0. DO NOT EDIT.
|
||||
|
||||
package topologyupdater
|
||||
|
||||
|
@ -44,3 +44,18 @@ func (_m *MockNodeTopologyClient) UpdateNodeTopology(ctx context.Context, in *No
|
|||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
type NewMockNodeTopologyClientT interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockNodeTopologyClient creates a new instance of MockNodeTopologyClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockNodeTopologyClient(t NewMockNodeTopologyClientT) *MockNodeTopologyClient {
|
||||
mock := &MockNodeTopologyClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Code generated by mockery v1.0.0. DO NOT EDIT.
|
||||
// Code generated by mockery v2.13.0. DO NOT EDIT.
|
||||
|
||||
package source
|
||||
|
||||
|
@ -59,3 +59,18 @@ func (_m *MockLabelSource) Priority() int {
|
|||
|
||||
return r0
|
||||
}
|
||||
|
||||
type NewMockLabelSourceT interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}
|
||||
|
||||
// NewMockLabelSource creates a new instance of MockLabelSource. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
func NewMockLabelSource(t NewMockLabelSourceT) *MockLabelSource {
|
||||
mock := &MockLabelSource{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
|
||||
package source
|
||||
|
||||
//go:generate mockery --name=LabelSource --inpkg
|
||||
//go:generate mockery --name=LabelSource --inpackage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
|
Loading…
Add table
Reference in a new issue