diff --git a/Makefile b/Makefile index 32f87faeff4..336624526c7 100644 --- a/Makefile +++ b/Makefile @@ -54,8 +54,14 @@ tidy: ## Update dependencies clean: ## Clean up the build artifacts $(Q)rm -rf build -cli-doc: ## Generate CLI Documentation - ./hack/doc/gen_cli_doc.sh +gen-cli-doc: ## Generate CLI documentation + ./hack/generate/gen-cli-doc.sh + +gen-test-framework: install ## Run generate commands to update test/test-framework + ./hack/generate/gen-test-framework.sh + +generate: gen-cli-doc gen-test-framework ## Run all generate targets +.PHONY: generate gen-cli-doc gen-test-framework # Build/install/release the SDK. .PHONY: install release_builds release @@ -112,7 +118,7 @@ test: test-unit ## Run the tests test-markdown test/markdown: ./hack/ci/marker -test-sanity test/sanity: tidy +test-sanity test/sanity: tidy build/operator-sdk ./hack/tests/sanity-check.sh test-unit test/unit: ## Run the unit tests diff --git a/go.mod b/go.mod index 3be33cf3ab8..59ffe57291c 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,6 @@ require ( github.com/ghodss/yaml v1.0.1-0.20180820084758-c7ce16629ff4 github.com/go-logr/logr v0.1.0 github.com/go-logr/zapr v0.1.1 - github.com/go-openapi/spec v0.19.0 github.com/gobuffalo/packr v1.30.1 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/huandu/xstrings v1.2.0 // indirect diff --git a/hack/check_error_log_msg_format.sh b/hack/check-error-log-msg-format.sh similarity index 100% rename from hack/check_error_log_msg_format.sh rename to hack/check-error-log-msg-format.sh diff --git a/hack/check_license.sh b/hack/check-license.sh similarity index 100% rename from hack/check_license.sh rename to hack/check-license.sh diff --git a/hack/doc/gen_cli_doc.sh b/hack/doc/gen_cli_doc.sh deleted file mode 100755 index b12f5e1daaa..00000000000 --- a/hack/doc/gen_cli_doc.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -go run ./hack/doc/gen-cli-doc.go diff --git a/hack/doc/gen-cli-doc.go b/hack/generate/gen-cli-doc.go similarity index 100% rename from hack/doc/gen-cli-doc.go rename to hack/generate/gen-cli-doc.go diff --git a/hack/generate/gen-cli-doc.sh b/hack/generate/gen-cli-doc.sh new file mode 100755 index 00000000000..5b716f55981 --- /dev/null +++ b/hack/generate/gen-cli-doc.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +go run ./hack/generate/gen-cli-doc.go diff --git a/hack/generate/gen-test-framework.sh b/hack/generate/gen-test-framework.sh new file mode 100755 index 00000000000..38f96119810 --- /dev/null +++ b/hack/generate/gen-test-framework.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +############################# +# Make sure that test/test-framework is updated according to the current source code +############################# + +set -ex + +source hack/lib/test_lib.sh + +# Define vars +DOCKERFILE="build/Dockerfile" + +# Go inside of the mock data test project +cd test/test-framework + +# Create the required files in the mock test/test-framework just to allow run from it the oprator-sdk commands +echo > $DOCKERFILE +go mod init test-framework + +# Remove files that are required and created just to exec the commands. +trap_add 'rm -rf $DOCKERFILE go.mod go.sum' EXIT + +# Run gen commands +../../build/operator-sdk generate k8s +../../build/operator-sdk generate openapi + +# TODO(camilamacedo86): remove this when the openapi gen be set to false and it no longer is generated +# The following file is gen by openapi but it has not been committed in order to allow we clone and call the test locally in any path. +trap_add 'rm pkg/apis/cache/v1alpha1/zz_generated.openapi.go' EXIT \ No newline at end of file diff --git a/hack/tests/sanity-check.sh b/hack/tests/sanity-check.sh index 680e61a0457..d0e947c16a7 100755 --- a/hack/tests/sanity-check.sh +++ b/hack/tests/sanity-check.sh @@ -5,9 +5,10 @@ go mod tidy go vet ./... go fmt ./... -./hack/check_license.sh -./hack/check_error_log_msg_format.sh -./hack/doc/gen_cli_doc.sh +./hack/check-license.sh +./hack/check-error-log-msg-format.sh +./hack/generate/gen-cli-doc.sh +./hack/generate/gen-test-framework.sh # Make sure repo is still in a clean state. git diff --exit-code diff --git a/test/test-framework/pkg/apis/cache/v1alpha1/zz_generated.openapi.go b/test/test-framework/pkg/apis/cache/v1alpha1/zz_generated.openapi.go deleted file mode 100644 index e503445714f..00000000000 --- a/test/test-framework/pkg/apis/cache/v1alpha1/zz_generated.openapi.go +++ /dev/null @@ -1,221 +0,0 @@ -// +build !ignore_autogenerated - -// This file was autogenerated by openapi-gen. Do not edit it manually! - -package v1alpha1 - -import ( - spec "github.com/go-openapi/spec" - common "k8s.io/kube-openapi/pkg/common" -) - -func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition { - return map[string]common.OpenAPIDefinition{ - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.Memcached": schema_pkg_apis_cache_v1alpha1_Memcached(ref), - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRS": schema_pkg_apis_cache_v1alpha1_MemcachedRS(ref), - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRSSpec": schema_pkg_apis_cache_v1alpha1_MemcachedRSSpec(ref), - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRSStatus": schema_pkg_apis_cache_v1alpha1_MemcachedRSStatus(ref), - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedSpec": schema_pkg_apis_cache_v1alpha1_MemcachedSpec(ref), - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedStatus": schema_pkg_apis_cache_v1alpha1_MemcachedStatus(ref), - } -} - -func schema_pkg_apis_cache_v1alpha1_Memcached(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "Memcached is the Schema for the memcacheds API", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedSpec"), - }, - }, - "status": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedStatus"), - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedSpec", "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_cache_v1alpha1_MemcachedRS(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MemcachedRS is the Schema for the memcachedrs API", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "kind": { - SchemaProps: spec.SchemaProps{ - Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", - Type: []string{"string"}, - Format: "", - }, - }, - "apiVersion": { - SchemaProps: spec.SchemaProps{ - Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", - Type: []string{"string"}, - Format: "", - }, - }, - "metadata": { - SchemaProps: spec.SchemaProps{ - Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), - }, - }, - "spec": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRSSpec"), - }, - }, - "status": { - SchemaProps: spec.SchemaProps{ - Ref: ref("github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRSStatus"), - }, - }, - }, - }, - }, - Dependencies: []string{ - "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRSSpec", "github.com/operator-framework/operator-sdk/test/test-framework/pkg/apis/cache/v1alpha1.MemcachedRSStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, - } -} - -func schema_pkg_apis_cache_v1alpha1_MemcachedRSSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MemcachedRSSpec defines the desired state of MemcachedRS", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "numNodes": { - SchemaProps: spec.SchemaProps{ - Type: []string{"integer"}, - Format: "int32", - }, - }, - }, - Required: []string{"numNodes"}, - }, - }, - } -} - -func schema_pkg_apis_cache_v1alpha1_MemcachedRSStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MemcachedRSStatus defines the observed state of MemcachedRS", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "nodeList": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "set", - }, - }, - SchemaProps: spec.SchemaProps{ - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - "test": { - SchemaProps: spec.SchemaProps{ - Type: []string{"boolean"}, - Format: "", - }, - }, - }, - Required: []string{"nodeList", "test"}, - }, - }, - } -} - -func schema_pkg_apis_cache_v1alpha1_MemcachedSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MemcachedSpec defines the desired state of Memcached", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "size": { - SchemaProps: spec.SchemaProps{ - Description: "Size is the size of the memcached deployment", - Type: []string{"integer"}, - Format: "int32", - }, - }, - }, - Required: []string{"size"}, - }, - }, - } -} - -func schema_pkg_apis_cache_v1alpha1_MemcachedStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Description: "MemcachedStatus defines the observed state of Memcached", - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "nodes": { - VendorExtensible: spec.VendorExtensible{ - Extensions: spec.Extensions{ - "x-kubernetes-list-type": "set", - }, - }, - SchemaProps: spec.SchemaProps{ - Description: "Nodes are the names of the memcached pods", - Type: []string{"array"}, - Items: &spec.SchemaOrArray{ - Schema: &spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"string"}, - Format: "", - }, - }, - }, - }, - }, - }, - Required: []string{"nodes"}, - }, - }, - } -}