From c86d50ecef07367197dec8891ae65aacb2b7bc88 Mon Sep 17 00:00:00 2001 From: Ricardo Katz Date: Thu, 21 Jul 2022 21:32:48 -0300 Subject: [PATCH] Move APIs to be used by both controller and configurer (#8854) --- hack/update-codegen.sh | 2 +- internal/ingress/controller/config/config.go | 2 +- internal/ingress/controller/controller.go | 2 +- internal/ingress/controller/controller_test.go | 2 +- internal/ingress/controller/endpoints.go | 2 +- internal/ingress/controller/endpoints_test.go | 2 +- internal/ingress/controller/location.go | 2 +- internal/ingress/controller/nginx.go | 2 +- internal/ingress/controller/nginx_test.go | 2 +- internal/ingress/controller/store/backend_ssl.go | 2 +- internal/ingress/controller/store/ingress.go | 2 +- internal/ingress/controller/store/ingress_annotation.go | 2 +- internal/ingress/controller/store/local_secret.go | 2 +- internal/ingress/controller/store/store.go | 2 +- internal/ingress/controller/store/store_test.go | 2 +- internal/ingress/controller/template/template.go | 2 +- internal/ingress/controller/template/template_test.go | 2 +- internal/ingress/controller/util.go | 2 +- internal/ingress/metric/collectors/controller.go | 2 +- internal/ingress/metric/collectors/controller_test.go | 2 +- internal/ingress/metric/dummy.go | 2 +- internal/ingress/metric/main.go | 2 +- internal/ingress/status/status.go | 2 +- internal/ingress/status/status_test.go | 2 +- internal/net/ssl/ssl.go | 2 +- {internal => pkg/apis}/ingress/sslcert.go | 0 {internal => pkg/apis}/ingress/types.go | 9 ++------- {internal => pkg/apis}/ingress/types_equals.go | 0 {internal => pkg/apis}/ingress/types_equals_test.go | 6 +++--- {internal => pkg/apis}/ingress/zz_generated.deepcopy.go | 0 30 files changed, 30 insertions(+), 35 deletions(-) rename {internal => pkg/apis}/ingress/sslcert.go (100%) rename {internal => pkg/apis}/ingress/types.go (98%) rename {internal => pkg/apis}/ingress/types_equals.go (100%) rename {internal => pkg/apis}/ingress/types_equals_test.go (96%) rename {internal => pkg/apis}/ingress/zz_generated.deepcopy.go (100%) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 9023a3a1ae..fadc676332 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -38,7 +38,7 @@ chmod +x ${CODEGEN_PKG}/generate-groups.sh # nginxingress:v1alpha1 \ # --output-base "$(dirname ${BASH_SOURCE})/../../.." ${CODEGEN_PKG}/generate-groups.sh "deepcopy" \ - k8s.io/ingress-nginx/internal k8s.io/ingress-nginx/internal \ + k8s.io/ingress-nginx/internal k8s.io/ingress-nginx/pkg/apis \ .:ingress \ --output-base "$(dirname ${BASH_SOURCE})/../../.." \ --go-header-file ${SCRIPT_ROOT}/hack/boilerplate/boilerplate.generated.go.txt diff --git a/internal/ingress/controller/config/config.go b/internal/ingress/controller/config/config.go index dfc90c385e..4ee2df965b 100644 --- a/internal/ingress/controller/config/config.go +++ b/internal/ingress/controller/config/config.go @@ -24,8 +24,8 @@ import ( apiv1 "k8s.io/api/core/v1" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/defaults" + "k8s.io/ingress-nginx/pkg/apis/ingress" "k8s.io/ingress-nginx/pkg/util/runtime" ) diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index 44385f175d..d0f85bb011 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -32,7 +32,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/annotations" "k8s.io/ingress-nginx/internal/ingress/annotations/log" "k8s.io/ingress-nginx/internal/ingress/annotations/parser" @@ -45,6 +44,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/metric/collectors" "k8s.io/ingress-nginx/internal/k8s" "k8s.io/ingress-nginx/internal/nginx" + "k8s.io/ingress-nginx/pkg/apis/ingress" "k8s.io/klog/v2" ) diff --git a/internal/ingress/controller/controller_test.go b/internal/ingress/controller/controller_test.go index 0e8ae9d62e..f875632e09 100644 --- a/internal/ingress/controller/controller_test.go +++ b/internal/ingress/controller/controller_test.go @@ -39,7 +39,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/kubernetes/fake" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" "k8s.io/ingress-nginx/internal/ingress/annotations" "k8s.io/ingress-nginx/internal/ingress/annotations/canary" diff --git a/internal/ingress/controller/endpoints.go b/internal/ingress/controller/endpoints.go index 26d7f298e7..5615fadea1 100644 --- a/internal/ingress/controller/endpoints.go +++ b/internal/ingress/controller/endpoints.go @@ -29,8 +29,8 @@ import ( corev1 "k8s.io/api/core/v1" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/k8s" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // getEndpoints returns a list of Endpoint structs for a given service/target port combination. diff --git a/internal/ingress/controller/endpoints_test.go b/internal/ingress/controller/endpoints_test.go index 83c8e18375..f38ffabe78 100644 --- a/internal/ingress/controller/endpoints_test.go +++ b/internal/ingress/controller/endpoints_test.go @@ -22,7 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) func TestGetEndpoints(t *testing.T) { diff --git a/internal/ingress/controller/location.go b/internal/ingress/controller/location.go index d40e88960f..9776f8c87d 100644 --- a/internal/ingress/controller/location.go +++ b/internal/ingress/controller/location.go @@ -21,7 +21,7 @@ import ( "strings" networking "k8s.io/api/networking/v1" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) var ( diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 05b3393f1a..d0f4abe273 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -47,7 +47,6 @@ import ( "k8s.io/ingress-nginx/pkg/tcpproxy" adm_controller "k8s.io/ingress-nginx/internal/admission/controller" - "k8s.io/ingress-nginx/internal/ingress" ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config" "k8s.io/ingress-nginx/internal/ingress/controller/process" "k8s.io/ingress-nginx/internal/ingress/controller/store" @@ -59,6 +58,7 @@ import ( "k8s.io/ingress-nginx/internal/net/ssl" "k8s.io/ingress-nginx/internal/nginx" "k8s.io/ingress-nginx/internal/task" + "k8s.io/ingress-nginx/pkg/apis/ingress" "k8s.io/ingress-nginx/pkg/util/file" klog "k8s.io/klog/v2" diff --git a/internal/ingress/controller/nginx_test.go b/internal/ingress/controller/nginx_test.go index d168efffd2..c2c71b7974 100644 --- a/internal/ingress/controller/nginx_test.go +++ b/internal/ingress/controller/nginx_test.go @@ -32,8 +32,8 @@ import ( apiv1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/nginx" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) func TestIsDynamicConfigurationEnough(t *testing.T) { diff --git a/internal/ingress/controller/store/backend_ssl.go b/internal/ingress/controller/store/backend_ssl.go index 96164b95ea..6f0fcf189d 100644 --- a/internal/ingress/controller/store/backend_ssl.go +++ b/internal/ingress/controller/store/backend_ssl.go @@ -24,7 +24,7 @@ import ( networking "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" klog "k8s.io/klog/v2" diff --git a/internal/ingress/controller/store/ingress.go b/internal/ingress/controller/store/ingress.go index 1d8ccb3428..d05b2624bb 100644 --- a/internal/ingress/controller/store/ingress.go +++ b/internal/ingress/controller/store/ingress.go @@ -19,7 +19,7 @@ package store import ( networking "k8s.io/api/networking/v1" "k8s.io/client-go/tools/cache" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // IngressLister makes a Store that lists Ingress. diff --git a/internal/ingress/controller/store/ingress_annotation.go b/internal/ingress/controller/store/ingress_annotation.go index c9c596d1ed..b70ceb1c63 100644 --- a/internal/ingress/controller/store/ingress_annotation.go +++ b/internal/ingress/controller/store/ingress_annotation.go @@ -18,7 +18,7 @@ package store import ( "k8s.io/client-go/tools/cache" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // IngressWithAnnotationsLister makes a Store that lists Ingress rules with annotations already parsed diff --git a/internal/ingress/controller/store/local_secret.go b/internal/ingress/controller/store/local_secret.go index ee3ced3987..8b26e7a530 100644 --- a/internal/ingress/controller/store/local_secret.go +++ b/internal/ingress/controller/store/local_secret.go @@ -21,7 +21,7 @@ import ( "k8s.io/client-go/tools/cache" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // SSLCertTracker holds a store of referenced Secrets in Ingress rules diff --git a/internal/ingress/controller/store/store.go b/internal/ingress/controller/store/store.go index 72300a4de8..239fbaaf5a 100644 --- a/internal/ingress/controller/store/store.go +++ b/internal/ingress/controller/store/store.go @@ -48,7 +48,6 @@ import ( "k8s.io/ingress-nginx/pkg/util/file" klog "k8s.io/klog/v2" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/annotations" "k8s.io/ingress-nginx/internal/ingress/annotations/parser" ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config" @@ -58,6 +57,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/errors" "k8s.io/ingress-nginx/internal/ingress/resolver" "k8s.io/ingress-nginx/internal/k8s" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // IngressFilterFunc decides if an Ingress should be omitted or not diff --git a/internal/ingress/controller/store/store_test.go b/internal/ingress/controller/store/store_test.go index 4868f792f5..9b8947f9c2 100644 --- a/internal/ingress/controller/store/store_test.go +++ b/internal/ingress/controller/store/store_test.go @@ -36,9 +36,9 @@ import ( "k8s.io/client-go/tools/cache" "sigs.k8s.io/controller-runtime/pkg/envtest" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/annotations/parser" "k8s.io/ingress-nginx/internal/ingress/controller/ingressclass" + "k8s.io/ingress-nginx/pkg/apis/ingress" "k8s.io/ingress-nginx/test/e2e/framework" ) diff --git a/internal/ingress/controller/template/template.go b/internal/ingress/controller/template/template.go index a331c196af..8d4cb6e752 100644 --- a/internal/ingress/controller/template/template.go +++ b/internal/ingress/controller/template/template.go @@ -40,12 +40,12 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/klog/v2" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/annotations/influxdb" "k8s.io/ingress-nginx/internal/ingress/annotations/parser" "k8s.io/ingress-nginx/internal/ingress/annotations/ratelimit" "k8s.io/ingress-nginx/internal/ingress/controller/config" ing_net "k8s.io/ingress-nginx/internal/net" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) const ( diff --git a/internal/ingress/controller/template/template_test.go b/internal/ingress/controller/template/template_test.go index a741919ed7..cb1ebd1b70 100644 --- a/internal/ingress/controller/template/template_test.go +++ b/internal/ingress/controller/template/template_test.go @@ -34,7 +34,6 @@ import ( networking "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/annotations/authreq" "k8s.io/ingress-nginx/internal/ingress/annotations/influxdb" "k8s.io/ingress-nginx/internal/ingress/annotations/modsecurity" @@ -43,6 +42,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/annotations/rewrite" "k8s.io/ingress-nginx/internal/ingress/controller/config" "k8s.io/ingress-nginx/internal/nginx" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) func init() { diff --git a/internal/ingress/controller/util.go b/internal/ingress/controller/util.go index a8232ed0e3..6562dd17cb 100644 --- a/internal/ingress/controller/util.go +++ b/internal/ingress/controller/util.go @@ -28,7 +28,7 @@ import ( api "k8s.io/api/core/v1" networking "k8s.io/api/networking/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" klog "k8s.io/klog/v2" ) diff --git a/internal/ingress/metric/collectors/controller.go b/internal/ingress/metric/collectors/controller.go index e4e2655c80..5822f0d57d 100644 --- a/internal/ingress/metric/collectors/controller.go +++ b/internal/ingress/metric/collectors/controller.go @@ -22,7 +22,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" "k8s.io/ingress-nginx/version" "k8s.io/klog/v2" ) diff --git a/internal/ingress/metric/collectors/controller_test.go b/internal/ingress/metric/collectors/controller_test.go index bc9f21c60c..ef80bc96a9 100644 --- a/internal/ingress/metric/collectors/controller_test.go +++ b/internal/ingress/metric/collectors/controller_test.go @@ -24,7 +24,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) func TestControllerCounters(t *testing.T) { diff --git a/internal/ingress/metric/dummy.go b/internal/ingress/metric/dummy.go index 8360dc87db..4a6366b84d 100644 --- a/internal/ingress/metric/dummy.go +++ b/internal/ingress/metric/dummy.go @@ -18,7 +18,7 @@ package metric import ( "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // NewDummyCollector returns a dummy metric collector diff --git a/internal/ingress/metric/main.go b/internal/ingress/metric/main.go index a0aea1e71a..b3323c7fe1 100644 --- a/internal/ingress/metric/main.go +++ b/internal/ingress/metric/main.go @@ -25,8 +25,8 @@ import ( "k8s.io/klog/v2" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/metric/collectors" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // Collector defines the interface for a metric collector diff --git a/internal/ingress/status/status.go b/internal/ingress/status/status.go index bf79701fc5..2e53682a02 100644 --- a/internal/ingress/status/status.go +++ b/internal/ingress/status/status.go @@ -34,9 +34,9 @@ import ( "k8s.io/apimachinery/pkg/util/wait" clientset "k8s.io/client-go/kubernetes" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/k8s" "k8s.io/ingress-nginx/internal/task" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) // UpdateInterval defines the time interval, in seconds, in diff --git a/internal/ingress/status/status_test.go b/internal/ingress/status/status_test.go index fefca5ff2a..d4ef09e7ce 100644 --- a/internal/ingress/status/status_test.go +++ b/internal/ingress/status/status_test.go @@ -28,10 +28,10 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" testclient "k8s.io/client-go/kubernetes/fake" - "k8s.io/ingress-nginx/internal/ingress" "k8s.io/ingress-nginx/internal/ingress/controller/ingressclass" "k8s.io/ingress-nginx/internal/k8s" "k8s.io/ingress-nginx/internal/task" + "k8s.io/ingress-nginx/pkg/apis/ingress" ) func buildLoadBalancerIngressByIP() []apiv1.LoadBalancerIngress { diff --git a/internal/net/ssl/ssl.go b/internal/net/ssl/ssl.go index bdbdb2e065..05ec10bc58 100644 --- a/internal/net/ssl/ssl.go +++ b/internal/net/ssl/ssl.go @@ -40,7 +40,7 @@ import ( "github.com/zakjan/cert-chain-resolver/certUtil" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/ingress-nginx/internal/ingress" + "k8s.io/ingress-nginx/pkg/apis/ingress" ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config" "k8s.io/ingress-nginx/pkg/util/file" diff --git a/internal/ingress/sslcert.go b/pkg/apis/ingress/sslcert.go similarity index 100% rename from internal/ingress/sslcert.go rename to pkg/apis/ingress/sslcert.go diff --git a/internal/ingress/types.go b/pkg/apis/ingress/types.go similarity index 98% rename from internal/ingress/types.go rename to pkg/apis/ingress/types.go index db4f37f990..8460ee6842 100644 --- a/internal/ingress/types.go +++ b/pkg/apis/ingress/types.go @@ -42,13 +42,8 @@ import ( "k8s.io/ingress-nginx/internal/ingress/annotations/rewrite" ) -var ( - // DefaultSSLDirectory defines the location where the SSL certificates will be generated - // This directory contains all the SSL certificates that are specified in Ingress rules. - // The name of each file is -.pem. The content is the concatenated - // certificate and key. - DefaultSSLDirectory = "/ingress-controller/ssl" -) +// TODO: The API shouldn't be importing structs from annotation code. Instead we probably want a conversion from internal +// to API object, or see how much effort is to move the structs of annotations to become an "API'ish" as well // Configuration holds the definition of all the parts required to describe all // ingresses reachable by the ingress controller (using a filter by namespace) diff --git a/internal/ingress/types_equals.go b/pkg/apis/ingress/types_equals.go similarity index 100% rename from internal/ingress/types_equals.go rename to pkg/apis/ingress/types_equals.go diff --git a/internal/ingress/types_equals_test.go b/pkg/apis/ingress/types_equals_test.go similarity index 96% rename from internal/ingress/types_equals_test.go rename to pkg/apis/ingress/types_equals_test.go index 8119d26c78..78d29d46c8 100644 --- a/internal/ingress/types_equals_test.go +++ b/pkg/apis/ingress/types_equals_test.go @@ -25,19 +25,19 @@ import ( ) func TestEqualConfiguration(t *testing.T) { - ap, _ := filepath.Abs("../../test/manifests/configuration-a.json") + ap, _ := filepath.Abs("../../../test/manifests/configuration-a.json") a, err := readJSON(ap) if err != nil { t.Errorf("unexpected error reading JSON file: %v", err) } - bp, _ := filepath.Abs("../../test/manifests/configuration-b.json") + bp, _ := filepath.Abs("../../../test/manifests/configuration-b.json") b, err := readJSON(bp) if err != nil { t.Errorf("unexpected error reading JSON file: %v", err) } - cp, _ := filepath.Abs("../../test/manifests/configuration-c.json") + cp, _ := filepath.Abs("../../../test/manifests/configuration-c.json") c, err := readJSON(cp) if err != nil { t.Errorf("unexpected error reading JSON file: %v", err) diff --git a/internal/ingress/zz_generated.deepcopy.go b/pkg/apis/ingress/zz_generated.deepcopy.go similarity index 100% rename from internal/ingress/zz_generated.deepcopy.go rename to pkg/apis/ingress/zz_generated.deepcopy.go