Fixed lint and unit tests
This PS makes sure we have linter and unit tests processed. The code has been reformatted to adhere to Go's code formatting conventions. Change-Id: I31f15d6d6c4b9bda7e3837941b6c9c3c3735aea7
This commit is contained in:
parent
5dcc0bf0b2
commit
4ae2c3a101
25
Makefile
25
Makefile
@ -49,6 +49,8 @@ endif
|
||||
|
||||
_BASE_IMAGE_ARG := $(if $(UBUNTU_BASE_IMAGE),--build-arg FROM="${UBUNTU_BASE_IMAGE}" ,)
|
||||
|
||||
MAKE_TARGET := build
|
||||
|
||||
# CONTAINER_TOOL defines the container tool to be used for building images.
|
||||
# Be aware that the target commands are only tested with Docker which is
|
||||
# scaffolded by default. However, you might want to replace it to use other
|
||||
@ -69,7 +71,7 @@ PKG := ./...
|
||||
TESTS := .
|
||||
|
||||
.PHONY: all
|
||||
all: build
|
||||
all: build unit-tests
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
@ -77,9 +79,17 @@ build:
|
||||
@CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o bin/kubernetes-entrypoint
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
lint: build
|
||||
@go run ${LINTER_CMD} --config ${LINTER_CONFIG}
|
||||
|
||||
.PHONY: fmt
|
||||
fmt: ## Run go fmt against code.
|
||||
go fmt ./...
|
||||
|
||||
.PHONY: vet
|
||||
vet: ## Run go vet against code.
|
||||
go vet ./...
|
||||
|
||||
.PHONY: docker-image
|
||||
docker-image:
|
||||
ifeq ($(USE_PROXY), true)
|
||||
@ -89,6 +99,7 @@ ifeq ($(USE_PROXY), true)
|
||||
--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
|
||||
-f images/Dockerfile.$(DISTRO) \
|
||||
$(_BASE_IMAGE_ARG) \
|
||||
--build-arg MAKE_TARGET=$(MAKE_TARGET) \
|
||||
--build-arg http_proxy=$(PROXY) \
|
||||
--build-arg https_proxy=$(PROXY) \
|
||||
--build-arg HTTP_PROXY=$(PROXY) \
|
||||
@ -101,6 +112,7 @@ else
|
||||
--label "org.opencontainers.image.created=$(shell date --rfc-3339=seconds --utc)" \
|
||||
--label "org.opencontainers.image.title=$(IMAGE_NAME)" \
|
||||
-f images/Dockerfile.$(DISTRO) \
|
||||
--build-arg MAKE_TARGET=$(MAKE_TARGET) \
|
||||
$(_BASE_IMAGE_ARG) .
|
||||
endif
|
||||
ifeq ($(PUSH_IMAGE), true)
|
||||
@ -117,15 +129,14 @@ check-docker:
|
||||
images: check-docker docker-image
|
||||
|
||||
.PHONY: docker-image-unit-tests
|
||||
docker-image-unit-tests: DOCKER_MAKE_TARGET = unit-tests
|
||||
docker-image-unit-tests: DOCKER_TARGET_STAGE = builder
|
||||
docker-image-unit-tests: MAKE_TARGET = unit-tests
|
||||
docker-image-unit-tests: docker-image
|
||||
|
||||
.PHONY: docker-image-lint
|
||||
docker-image-lint: DOCKER_MAKE_TARGET = lint
|
||||
docker-image-lint: DOCKER_TARGET_STAGE = builder
|
||||
docker-image-lint: MAKE_TARGET = lint
|
||||
docker-image-lint: docker-image
|
||||
|
||||
|
||||
.PHONY: get-modules
|
||||
get-modules:
|
||||
@go mod download
|
||||
@ -135,5 +146,5 @@ clean:
|
||||
@rm -rf bin
|
||||
|
||||
.PHONY: unit-test
|
||||
unit-tests:
|
||||
unit-tests: build
|
||||
@go test -v ./...
|
||||
|
@ -40,6 +40,7 @@ func (c Client) Jobs(namespace string) v1batch.JobInterface {
|
||||
func (c Client) Endpoints(namespace string) v1core.EndpointsInterface {
|
||||
return c.client.CoreV1().Endpoints(namespace)
|
||||
}
|
||||
|
||||
func (c Client) DaemonSets(namespace string) appsv1.DaemonSetInterface {
|
||||
return c.client.AppsV1().DaemonSets(namespace)
|
||||
}
|
||||
@ -48,7 +49,10 @@ func (c Client) Services(namespace string) v1core.ServiceInterface {
|
||||
return c.client.CoreV1().Services(namespace)
|
||||
}
|
||||
|
||||
func (c Client) CustomResource(ctx context.Context, apiVersion, kind, namespace, name string) (*unstructured.Unstructured, error) {
|
||||
func (c Client) CustomResource(
|
||||
ctx context.Context,
|
||||
apiVersion, kind, namespace, name string,
|
||||
) (*unstructured.Unstructured, error) {
|
||||
apiResourceList, err := c.client.Discovery().ServerResourcesForGroupVersion(apiVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
8
dependencies/config/config.go
vendored
8
dependencies/config/config.go
vendored
@ -64,13 +64,14 @@ func NewConfig(name string, prefix string) (*Config, error) {
|
||||
params: configParams{
|
||||
IP: ip,
|
||||
IP_ERLANG: strings.Replace(ip, ".", ",", -1),
|
||||
HOSTNAME: hostname},
|
||||
HOSTNAME: hostname,
|
||||
},
|
||||
prefix: prefix,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c Config) IsResolved(ctx context.Context, entrypoint entry.EntrypointInterface) (bool, error) {
|
||||
//Create directory to ensure it exists
|
||||
// Create directory to ensure it exists
|
||||
if err := createDirectory(c.name); err != nil {
|
||||
return false, fmt.Errorf("couldn't create directory: %v", err)
|
||||
}
|
||||
@ -78,7 +79,6 @@ func (c Config) IsResolved(ctx context.Context, entrypoint entry.EntrypointInter
|
||||
return false, fmt.Errorf("cannot template %s: %v", c.name, err)
|
||||
}
|
||||
return true, nil
|
||||
|
||||
}
|
||||
|
||||
func (c Config) createAndTemplateConfig() error {
|
||||
@ -100,7 +100,7 @@ func getSrcConfig(prefix string, config string) (srcConfig string) {
|
||||
}
|
||||
|
||||
func createDirectory(file string) error {
|
||||
return os.MkdirAll(filepath.Dir(file), 0755)
|
||||
return os.MkdirAll(filepath.Dir(file), 0o755)
|
||||
}
|
||||
|
||||
func (c Config) String() string {
|
||||
|
15
dependencies/config/config_test.go
vendored
15
dependencies/config/config_test.go
vendored
@ -24,10 +24,12 @@ const (
|
||||
templatePrefix = "/tmp/templates"
|
||||
)
|
||||
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
var testConfigContents string
|
||||
var testConfigPath string
|
||||
var testTemplatePath string
|
||||
var (
|
||||
testEntrypoint entrypoint.EntrypointInterface
|
||||
testConfigContents string
|
||||
testConfigPath string
|
||||
testTemplatePath string
|
||||
)
|
||||
|
||||
// var testClient cli.ClientInterface
|
||||
|
||||
@ -54,11 +56,11 @@ func teardownOsEnvironment() (err error) {
|
||||
|
||||
func setupConfigTemplate(templatePath string) error {
|
||||
configContent := []byte(testConfigContents)
|
||||
if err := os.MkdirAll(filepath.Dir(templatePath), 0755); err != nil {
|
||||
if err := os.MkdirAll(filepath.Dir(templatePath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(templatePath, configContent, 0644); err != nil {
|
||||
if err := os.WriteFile(templatePath, configContent, 0o644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -78,7 +80,6 @@ func teardownConfigTemplate() (err error) {
|
||||
}
|
||||
|
||||
var _ = Describe("Config", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
err := setupOsEnvironment()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
2
dependencies/container/container.go
vendored
2
dependencies/container/container.go
vendored
@ -30,7 +30,6 @@ func init() {
|
||||
os.Exit(1)
|
||||
}
|
||||
if containerDeps := env.SplitEnvToDeps(containerEnv); containerDeps != nil {
|
||||
|
||||
if len(containerDeps) > 0 {
|
||||
for _, dep := range containerDeps {
|
||||
entry.Register(NewContainer(dep.Name))
|
||||
@ -41,7 +40,6 @@ func init() {
|
||||
|
||||
func NewContainer(name string) Container {
|
||||
return Container{name: name}
|
||||
|
||||
}
|
||||
|
||||
func (c Container) IsResolved(ctx context.Context, entrypoint entry.EntrypointInterface) (bool, error) {
|
||||
|
1
dependencies/container/container_test.go
vendored
1
dependencies/container/container_test.go
vendored
@ -19,7 +19,6 @@ const (
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
|
||||
var _ = Describe("Container", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
err := os.Setenv(podEnvVariableName, mocks.PodEnvVariableValue)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
1
dependencies/daemonset/daemonset.go
vendored
1
dependencies/daemonset/daemonset.go
vendored
@ -51,7 +51,6 @@ func NewDaemonset(name string, namespace string) (*Daemonset, error) {
|
||||
func (d Daemonset) IsResolved(ctx context.Context, entrypoint entry.EntrypointInterface) (bool, error) {
|
||||
var myPodName string
|
||||
daemonset, err := entrypoint.Client().DaemonSets(d.namespace).Get(ctx, d.name, metav1.GetOptions{})
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
2
dependencies/daemonset/daemonset_test.go
vendored
2
dependencies/daemonset/daemonset_test.go
vendored
@ -20,7 +20,6 @@ const (
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
|
||||
var _ = Describe("Daemonset", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
err := os.Setenv(PodNameEnvVar, podEnvVariableValue)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -102,7 +101,6 @@ var _ = Describe("Daemonset", func() {
|
||||
|
||||
Expect(isResolved).To(BeTrue())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
})
|
||||
|
||||
It("checks resolution of an incorrect daemonset namespace", func() {
|
||||
|
8
dependencies/job/job_test.go
vendored
8
dependencies/job/job_test.go
vendored
@ -11,8 +11,10 @@ import (
|
||||
"opendev.org/airship/kubernetes-entrypoint/mocks"
|
||||
)
|
||||
|
||||
const testJobName = "TEST_JOB_NAME"
|
||||
const testJobNamespace = "TEST_JOB_NAMESPACE"
|
||||
const (
|
||||
testJobName = "TEST_JOB_NAME"
|
||||
testJobNamespace = "TEST_JOB_NAMESPACE"
|
||||
)
|
||||
|
||||
var testLabels = map[string]string{
|
||||
"k1": "v1",
|
||||
@ -21,7 +23,6 @@ var testLabels = map[string]string{
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
|
||||
var _ = Describe("Job", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
testEntrypoint = mocks.NewEntrypoint()
|
||||
})
|
||||
@ -78,5 +79,4 @@ var _ = Describe("Job", func() {
|
||||
Expect(isResolved).To(Equal(false))
|
||||
Expect(err.Error()).To(Equal(fmt.Sprintf(FailingStatusFormat, job)))
|
||||
})
|
||||
|
||||
})
|
||||
|
7
dependencies/pod/pod_test.go
vendored
7
dependencies/pod/pod_test.go
vendored
@ -18,11 +18,12 @@ const (
|
||||
requireSameNode = true
|
||||
)
|
||||
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
var testLabels = map[string]string{"foo": "bar"}
|
||||
var (
|
||||
testEntrypoint entrypoint.EntrypointInterface
|
||||
testLabels = map[string]string{"foo": "bar"}
|
||||
)
|
||||
|
||||
var _ = Describe("Pod", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
err := os.Setenv(PodNameEnvVar, podEnvVariableValue)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
1
dependencies/service/service.go
vendored
1
dependencies/service/service.go
vendored
@ -33,7 +33,6 @@ func NewService(name string, namespace string) Service {
|
||||
name: name,
|
||||
namespace: namespace,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s Service) IsResolved(ctx context.Context, entrypoint entry.EntrypointInterface) (bool, error) {
|
||||
|
7
dependencies/service/service_test.go
vendored
7
dependencies/service/service_test.go
vendored
@ -11,13 +11,14 @@ import (
|
||||
"opendev.org/airship/kubernetes-entrypoint/mocks"
|
||||
)
|
||||
|
||||
const testServiceName = "TEST_SERVICE_NAME"
|
||||
const testServiceNamespace = "TEST_SERVICE_NAMESPACE"
|
||||
const (
|
||||
testServiceName = "TEST_SERVICE_NAME"
|
||||
testServiceNamespace = "TEST_SERVICE_NAMESPACE"
|
||||
)
|
||||
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
|
||||
var _ = Describe("Service", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
testEntrypoint = mocks.NewEntrypoint()
|
||||
})
|
||||
|
1
dependencies/socket/socket_test.go
vendored
1
dependencies/socket/socket_test.go
vendored
@ -30,7 +30,6 @@ var (
|
||||
var testEntrypoint entrypoint.EntrypointInterface
|
||||
|
||||
var _ = Describe("Socket", func() {
|
||||
|
||||
// NOTE: It is impossible for a user to create a file that he does not
|
||||
// have access to, and thus it is impossible to write an isolated unit
|
||||
// test that checks for permission errors. That test is omitted from
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
|
||||
var dependencies []Resolver // List containing all dependencies to be resolved
|
||||
const (
|
||||
//DependencyPrefix is a prefix for env variables
|
||||
// DependencyPrefix is a prefix for env variables
|
||||
DependencyPrefix = "DEPENDENCY_"
|
||||
JsonSuffix = "_JSON"
|
||||
resolverSleepInterval = 2
|
||||
@ -76,9 +76,7 @@ func (e Entrypoint) Resolve() {
|
||||
time.Sleep(resolverSleepInterval * time.Second)
|
||||
}
|
||||
logger.Info.Printf("Dependency %v is resolved.", dep)
|
||||
|
||||
}(dep)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
|
@ -21,8 +21,10 @@ const (
|
||||
loggerInfoText = "Entrypoint INFO: "
|
||||
)
|
||||
|
||||
var testEntrypoint EntrypointInterface
|
||||
var testClient cli.ClientInterface
|
||||
var (
|
||||
testEntrypoint EntrypointInterface
|
||||
testClient cli.ClientInterface
|
||||
)
|
||||
|
||||
type dummyResolver struct {
|
||||
name string
|
||||
@ -32,6 +34,7 @@ type dummyResolver struct {
|
||||
func (d dummyResolver) IsResolved(ctx context.Context, entry EntrypointInterface) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (d dummyResolver) GetName() (name string) {
|
||||
return d.name
|
||||
}
|
||||
@ -50,7 +53,6 @@ func registerNilResolver() {
|
||||
}
|
||||
|
||||
var _ = Describe("Entrypoint", func() {
|
||||
|
||||
dummy := dummyResolver{name: dummyResolverName}
|
||||
|
||||
BeforeEach(func() {
|
||||
|
@ -6,11 +6,11 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
//Info logger
|
||||
// Info logger
|
||||
Info *log.Logger
|
||||
//Error logger
|
||||
// Error logger
|
||||
Error *log.Logger
|
||||
//Warning logger
|
||||
// Warning logger
|
||||
Warning *log.Logger
|
||||
)
|
||||
|
||||
|
@ -40,7 +40,10 @@ func (c Client) Jobs(namespace string) v1batch.JobInterface {
|
||||
return c.JobInterface
|
||||
}
|
||||
|
||||
func (c Client) CustomResource(ctx context.Context, apiVersion, namespace, resource, name string) (*unstructured.Unstructured, error) {
|
||||
func (c Client) CustomResource(
|
||||
ctx context.Context,
|
||||
apiVersion, namespace, resource, name string,
|
||||
) (*unstructured.Unstructured, error) {
|
||||
return c.FakeCustomResource, c.Err
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,7 @@ import (
|
||||
appsv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
|
||||
)
|
||||
|
||||
type dClient struct {
|
||||
}
|
||||
type dClient struct{}
|
||||
|
||||
const (
|
||||
SucceedingDaemonsetName = "DAEMONSET_SUCCEED"
|
||||
@ -26,15 +25,27 @@ const (
|
||||
NotReadyMatchLabelsDaemonsetName = "DAEMONSET_NOT_READY_MATCH_LABELS"
|
||||
)
|
||||
|
||||
func (d dClient) Create(ctx context.Context, daemonSet *v1.DaemonSet, opts metav1.CreateOptions) (*v1.DaemonSet, error) {
|
||||
func (d dClient) Create(
|
||||
ctx context.Context,
|
||||
daemonSet *v1.DaemonSet,
|
||||
opts metav1.CreateOptions,
|
||||
) (*v1.DaemonSet, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) Update(ctx context.Context, daemonSet *v1.DaemonSet, opts metav1.UpdateOptions) (*v1.DaemonSet, error) {
|
||||
func (d dClient) Update(
|
||||
ctx context.Context,
|
||||
daemonSet *v1.DaemonSet,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.DaemonSet, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) UpdateStatus(ctx context.Context, daemonSet *v1.DaemonSet, opts metav1.UpdateOptions) (*v1.DaemonSet, error) {
|
||||
func (d dClient) UpdateStatus(
|
||||
ctx context.Context,
|
||||
daemonSet *v1.DaemonSet,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.DaemonSet, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -42,11 +53,19 @@ func (d dClient) Delete(ctx context.Context, name string, opts metav1.DeleteOpti
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
func (d dClient) DeleteCollection(
|
||||
ctx context.Context,
|
||||
opts metav1.DeleteOptions,
|
||||
listOpts metav1.ListOptions,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.DaemonSet, error) {
|
||||
func (d dClient) Get(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts metav1.GetOptions,
|
||||
) (*v1.DaemonSet, error) {
|
||||
if name == FailingDaemonsetName || name == IncorrectNamespaceDaemonsetName {
|
||||
return nil, fmt.Errorf("mock daemonset didn't work")
|
||||
}
|
||||
@ -83,15 +102,30 @@ func (d dClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Inte
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.DaemonSet, err error) {
|
||||
func (d dClient) Patch(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
pt types.PatchType,
|
||||
data []byte,
|
||||
opts metav1.PatchOptions,
|
||||
subresources ...string,
|
||||
) (result *v1.DaemonSet, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) Apply(ctx context.Context, daemonSet *appsv1applyconfigurations.DaemonSetApplyConfiguration, opts metav1.ApplyOptions) (result *v1.DaemonSet, err error) {
|
||||
func (d dClient) Apply(
|
||||
ctx context.Context,
|
||||
daemonSet *appsv1applyconfigurations.DaemonSetApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.DaemonSet, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (d dClient) ApplyStatus(ctx context.Context, daemonSet *appsv1applyconfigurations.DaemonSetApplyConfiguration, opts metav1.ApplyOptions) (result *v1.DaemonSet, err error) {
|
||||
func (d dClient) ApplyStatus(
|
||||
ctx context.Context,
|
||||
daemonSet *appsv1applyconfigurations.DaemonSetApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.DaemonSet, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
|
@ -12,30 +12,49 @@ import (
|
||||
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
)
|
||||
|
||||
type eClient struct {
|
||||
}
|
||||
type eClient struct{}
|
||||
|
||||
const (
|
||||
MockEndpointError = "mock endpoint didnt work"
|
||||
)
|
||||
|
||||
func (e eClient) Create(ctx context.Context, endpoints *v1.Endpoints, opts metav1.CreateOptions) (*v1.Endpoints, error) {
|
||||
func (e eClient) Create(
|
||||
ctx context.Context,
|
||||
endpoints *v1.Endpoints,
|
||||
opts metav1.CreateOptions,
|
||||
) (*v1.Endpoints, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) Update(ctx context.Context, endpoints *v1.Endpoints, opts metav1.UpdateOptions) (*v1.Endpoints, error) {
|
||||
func (e eClient) Update(
|
||||
ctx context.Context,
|
||||
endpoints *v1.Endpoints,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Endpoints, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error {
|
||||
func (e eClient) Delete(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts metav1.DeleteOptions,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
func (e eClient) DeleteCollection(
|
||||
ctx context.Context,
|
||||
opts metav1.DeleteOptions,
|
||||
listOpts metav1.ListOptions,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Endpoints, error) {
|
||||
func (e eClient) Get(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts metav1.GetOptions,
|
||||
) (*v1.Endpoints, error) {
|
||||
if name == FailingServiceName {
|
||||
return nil, fmt.Errorf(MockEndpointError)
|
||||
}
|
||||
@ -60,19 +79,36 @@ func (e eClient) Get(ctx context.Context, name string, opts metav1.GetOptions) (
|
||||
return endpoint, nil
|
||||
}
|
||||
|
||||
func (e eClient) List(ctx context.Context, opts metav1.ListOptions) (*v1.EndpointsList, error) {
|
||||
func (e eClient) List(
|
||||
ctx context.Context,
|
||||
opts metav1.ListOptions,
|
||||
) (*v1.EndpointsList, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
||||
func (e eClient) Watch(
|
||||
ctx context.Context,
|
||||
opts metav1.ListOptions,
|
||||
) (watch.Interface, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Endpoints, err error) {
|
||||
func (e eClient) Patch(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
pt types.PatchType,
|
||||
data []byte,
|
||||
opts metav1.PatchOptions,
|
||||
subresources ...string,
|
||||
) (result *v1.Endpoints, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (e eClient) Apply(ctx context.Context, endpoints *corev1applyconfigurations.EndpointsApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Endpoints, err error) {
|
||||
func (e eClient) Apply(
|
||||
ctx context.Context,
|
||||
endpoints *corev1applyconfigurations.EndpointsApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Endpoints, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
|
48
mocks/job.go
48
mocks/job.go
@ -19,18 +19,29 @@ const (
|
||||
FailingJobLabel = "fail"
|
||||
)
|
||||
|
||||
type jClient struct {
|
||||
}
|
||||
type jClient struct{}
|
||||
|
||||
func (j jClient) Create(ctx context.Context, job *v1.Job, opts metav1.CreateOptions) (*v1.Job, error) {
|
||||
func (j jClient) Create(
|
||||
ctx context.Context,
|
||||
job *v1.Job,
|
||||
opts metav1.CreateOptions,
|
||||
) (*v1.Job, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (j jClient) Update(ctx context.Context, job *v1.Job, opts metav1.UpdateOptions) (*v1.Job, error) {
|
||||
func (j jClient) Update(
|
||||
ctx context.Context,
|
||||
job *v1.Job,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Job, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (j jClient) UpdateStatus(ctx context.Context, job *v1.Job, opts metav1.UpdateOptions) (*v1.Job, error) {
|
||||
func (j jClient) UpdateStatus(
|
||||
ctx context.Context,
|
||||
job *v1.Job,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Job, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -38,7 +49,11 @@ func (j jClient) Delete(ctx context.Context, name string, opts metav1.DeleteOpti
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (j jClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
func (j jClient) DeleteCollection(
|
||||
ctx context.Context,
|
||||
opts metav1.DeleteOptions,
|
||||
listOpts metav1.ListOptions,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -77,15 +92,30 @@ func (j jClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Inte
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (j jClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Job, err error) {
|
||||
func (j jClient) Patch(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
pt types.PatchType,
|
||||
data []byte,
|
||||
opts metav1.PatchOptions,
|
||||
subresources ...string,
|
||||
) (result *v1.Job, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (j jClient) Apply(ctx context.Context, job *batchv1applyconfigurations.JobApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Job, err error) {
|
||||
func (j jClient) Apply(
|
||||
ctx context.Context,
|
||||
job *batchv1applyconfigurations.JobApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Job, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (j jClient) ApplyStatus(ctx context.Context, job *batchv1applyconfigurations.JobApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Job, err error) {
|
||||
func (j jClient) ApplyStatus(
|
||||
ctx context.Context,
|
||||
job *batchv1applyconfigurations.JobApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Job, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
|
66
mocks/pod.go
66
mocks/pod.go
@ -17,8 +17,7 @@ import (
|
||||
|
||||
const MockContainerName = "TEST_CONTAINER"
|
||||
|
||||
type pClient struct {
|
||||
}
|
||||
type pClient struct{}
|
||||
|
||||
const (
|
||||
PodNotPresent = "NOT_PRESENT"
|
||||
@ -32,15 +31,27 @@ const (
|
||||
NoPodsMatchLabel = "NO_PODS"
|
||||
)
|
||||
|
||||
func (p pClient) Create(ctx context.Context, pod *v1.Pod, opts metav1.CreateOptions) (*v1.Pod, error) {
|
||||
func (p pClient) Create(
|
||||
ctx context.Context,
|
||||
pod *v1.Pod,
|
||||
opts metav1.CreateOptions,
|
||||
) (*v1.Pod, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) Update(ctx context.Context, pod *v1.Pod, opts metav1.UpdateOptions) (*v1.Pod, error) {
|
||||
func (p pClient) Update(
|
||||
ctx context.Context,
|
||||
pod *v1.Pod,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Pod, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) UpdateStatus(ctx context.Context, pod *v1.Pod, opts metav1.UpdateOptions) (*v1.Pod, error) {
|
||||
func (p pClient) UpdateStatus(
|
||||
ctx context.Context,
|
||||
pod *v1.Pod,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Pod, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -48,7 +59,11 @@ func (p pClient) Delete(ctx context.Context, name string, opts metav1.DeleteOpti
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
func (p pClient) DeleteCollection(
|
||||
ctx context.Context,
|
||||
opts metav1.DeleteOptions,
|
||||
listOpts metav1.ListOptions,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -111,23 +126,47 @@ func (p pClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Inte
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Pod, err error) {
|
||||
func (p pClient) Patch(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
pt types.PatchType,
|
||||
data []byte,
|
||||
opts metav1.PatchOptions,
|
||||
subresources ...string,
|
||||
) (result *v1.Pod, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) Apply(ctx context.Context, pod *corev1applyconfigurations.PodApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Pod, err error) {
|
||||
func (p pClient) Apply(
|
||||
ctx context.Context,
|
||||
pod *corev1applyconfigurations.PodApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Pod, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) ApplyStatus(ctx context.Context, pod *corev1applyconfigurations.PodApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Pod, err error) {
|
||||
func (p pClient) ApplyStatus(
|
||||
ctx context.Context,
|
||||
pod *corev1applyconfigurations.PodApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Pod, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) UpdateEphemeralContainers(ctx context.Context, podName string, pod *v1.Pod, opts metav1.UpdateOptions) (*v1.Pod, error) {
|
||||
func (p pClient) UpdateEphemeralContainers(
|
||||
ctx context.Context,
|
||||
podName string,
|
||||
pod *v1.Pod,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Pod, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (p pClient) Bind(ctx context.Context, binding *v1.Binding, opts metav1.CreateOptions) error {
|
||||
func (p pClient) Bind(
|
||||
ctx context.Context,
|
||||
binding *v1.Binding,
|
||||
opts metav1.CreateOptions,
|
||||
) error {
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -147,7 +186,10 @@ func (p pClient) GetLogs(name string, opts *v1.PodLogOptions) *restclient.Reques
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p pClient) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
func (p pClient) ProxyGet(
|
||||
scheme, name, port, path string,
|
||||
params map[string]string,
|
||||
) restclient.ResponseWrapper {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,7 @@ import (
|
||||
restclient "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type sClient struct {
|
||||
}
|
||||
type sClient struct{}
|
||||
|
||||
const (
|
||||
MockServiceError = "mock service didnt work"
|
||||
@ -23,15 +22,27 @@ const (
|
||||
FailingServiceName = "fail"
|
||||
)
|
||||
|
||||
func (s sClient) Create(ctx context.Context, service *v1.Service, opts metav1.CreateOptions) (*v1.Service, error) {
|
||||
func (s sClient) Create(
|
||||
ctx context.Context,
|
||||
service *v1.Service,
|
||||
opts metav1.CreateOptions,
|
||||
) (*v1.Service, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) Update(ctx context.Context, service *v1.Service, opts metav1.UpdateOptions) (*v1.Service, error) {
|
||||
func (s sClient) Update(
|
||||
ctx context.Context,
|
||||
service *v1.Service,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Service, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) UpdateStatus(ctx context.Context, service *v1.Service, opts metav1.UpdateOptions) (*v1.Service, error) {
|
||||
func (s sClient) UpdateStatus(
|
||||
ctx context.Context,
|
||||
service *v1.Service,
|
||||
opts metav1.UpdateOptions,
|
||||
) (*v1.Service, error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
@ -39,7 +50,11 @@ func (s sClient) Delete(ctx context.Context, name string, opts metav1.DeleteOpti
|
||||
return fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) Get(ctx context.Context, name string, opts metav1.GetOptions) (*v1.Service, error) {
|
||||
func (s sClient) Get(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
opts metav1.GetOptions,
|
||||
) (*v1.Service, error) {
|
||||
if name == FailingServiceName {
|
||||
return nil, fmt.Errorf(MockServiceError)
|
||||
}
|
||||
@ -56,19 +71,37 @@ func (s sClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Inte
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (result *v1.Service, err error) {
|
||||
func (s sClient) Patch(
|
||||
ctx context.Context,
|
||||
name string,
|
||||
pt types.PatchType,
|
||||
data []byte,
|
||||
opts metav1.PatchOptions,
|
||||
subresources ...string,
|
||||
) (result *v1.Service, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) Apply(ctx context.Context, service *corev1applyconfigurations.ServiceApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Service, err error) {
|
||||
func (s sClient) Apply(
|
||||
ctx context.Context,
|
||||
service *corev1applyconfigurations.ServiceApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Service, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) ApplyStatus(ctx context.Context, service *corev1applyconfigurations.ServiceApplyConfiguration, opts metav1.ApplyOptions) (result *v1.Service, err error) {
|
||||
func (s sClient) ApplyStatus(
|
||||
ctx context.Context,
|
||||
service *corev1applyconfigurations.ServiceApplyConfiguration,
|
||||
opts metav1.ApplyOptions,
|
||||
) (result *v1.Service, err error) {
|
||||
return nil, fmt.Errorf("not implemented")
|
||||
}
|
||||
|
||||
func (s sClient) ProxyGet(scheme, name, port, path string, params map[string]string) restclient.ResponseWrapper {
|
||||
func (s sClient) ProxyGet(
|
||||
scheme, name, port, path string,
|
||||
params map[string]string,
|
||||
) restclient.ResponseWrapper {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
20
playbooks/airship-kubernetes-entrypoint-lint.yaml
Normal file
20
playbooks/airship-kubernetes-entrypoint-lint.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
- hosts: primary
|
||||
tasks:
|
||||
- name: Run Linter
|
||||
block:
|
||||
- name: "make docker-image-lint"
|
||||
make:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
target: docker-image-lint
|
@ -12,16 +12,9 @@
|
||||
|
||||
- hosts: primary
|
||||
tasks:
|
||||
- name: Run Linter
|
||||
block:
|
||||
- name: "make docker-image-lint"
|
||||
make:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
target: docker-image-lint
|
||||
|
||||
- name: Run Unit Tests
|
||||
block:
|
||||
- name: "make docker-image-unit-tests"
|
||||
make:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
target: docker-image-unit-tests
|
||||
target: docker-image-unit-tests
|
@ -1,3 +1,4 @@
|
||||
//go:build tools
|
||||
// +build tools
|
||||
|
||||
package tools
|
||||
|
@ -24,7 +24,7 @@ func GetIp() (string, error) {
|
||||
if err != nil || len(address) == 0 {
|
||||
return "", fmt.Errorf("cannot get ip: %v", err)
|
||||
}
|
||||
//Take first element to get rid of subnet
|
||||
// Take first element to get rid of subnet
|
||||
ip := strings.Split(address[0].String(), "/")[0]
|
||||
return ip, nil
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
const failingNamespaceUtil = "foo:util"
|
||||
|
||||
var _ = Describe("Util", func() {
|
||||
|
||||
It("fails on trying to resolve a socket with namespace", func() {
|
||||
contains := ContainsSeparator(failingNamespaceUtil, "Util")
|
||||
Expect(contains).To(Equal(true))
|
||||
|
@ -16,6 +16,21 @@
|
||||
run: playbooks/airship-kubernetes-entrypoint-lint-unit.yaml
|
||||
nodeset: airship-kubernetes-entrypoint-single-node-focal
|
||||
|
||||
|
||||
- job:
|
||||
name: airship-kubernetes-entrypoint-lint
|
||||
timeout: 3600
|
||||
pre-run: playbooks/airship-kubernetes-entrypoint-deploy-docker.yaml
|
||||
run: playbooks/airship-kubernetes-entrypoint-lint.yaml
|
||||
nodeset: airship-kubernetes-entrypoint-single-node-focal
|
||||
|
||||
- job:
|
||||
name: airship-kubernetes-entrypoint-unit
|
||||
timeout: 3600
|
||||
pre-run: playbooks/airship-kubernetes-entrypoint-deploy-docker.yaml
|
||||
run: playbooks/airship-kubernetes-entrypoint-unit.yaml
|
||||
nodeset: airship-kubernetes-entrypoint-single-node-focal
|
||||
|
||||
- job:
|
||||
name: airship-kubernetes-entrypoint-docker-build-gate-ubuntu_focal
|
||||
timeout: 3600
|
||||
|
@ -13,11 +13,14 @@
|
||||
- project:
|
||||
check:
|
||||
jobs:
|
||||
- airship-kubernetes-entrypoint-lint-unit
|
||||
- airship-kubernetes-entrypoint-lint
|
||||
- airship-kubernetes-entrypoint-unit
|
||||
- airship-kubernetes-entrypoint-docker-build-gate-ubuntu_focal
|
||||
|
||||
gate:
|
||||
jobs:
|
||||
- airship-kubernetes-entrypoint-lint-unit
|
||||
- airship-kubernetes-entrypoint-lint
|
||||
- airship-kubernetes-entrypoint-unit
|
||||
- airship-kubernetes-entrypoint-docker-build-gate-ubuntu_focal
|
||||
post:
|
||||
jobs:
|
||||
|
Loading…
x
Reference in New Issue
Block a user