diff --git a/internal/ingress/annotations/authreq/main.go b/internal/ingress/annotations/authreq/main.go index b5dc4c70b5..b607f54828 100644 --- a/internal/ingress/annotations/authreq/main.go +++ b/internal/ingress/annotations/authreq/main.go @@ -28,7 +28,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/annotations/parser" ing_errors "k8s.io/ingress-nginx/internal/ingress/errors" "k8s.io/ingress-nginx/internal/ingress/resolver" - "k8s.io/ingress-nginx/internal/sets" + "k8s.io/ingress-nginx/pkg/util/sets" ) // Config returns external authentication configuration for an Ingress rule diff --git a/internal/ingress/annotations/globalratelimit/main.go b/internal/ingress/annotations/globalratelimit/main.go index c5763d0cb3..ea9fc46786 100644 --- a/internal/ingress/annotations/globalratelimit/main.go +++ b/internal/ingress/annotations/globalratelimit/main.go @@ -27,7 +27,7 @@ import ( ing_errors "k8s.io/ingress-nginx/internal/ingress/errors" "k8s.io/ingress-nginx/internal/ingress/resolver" "k8s.io/ingress-nginx/internal/net" - "k8s.io/ingress-nginx/internal/sets" + "k8s.io/ingress-nginx/pkg/util/sets" ) const defaultKey = "$remote_addr" diff --git a/internal/ingress/annotations/ipwhitelist/main.go b/internal/ingress/annotations/ipwhitelist/main.go index 38610ade67..63c049fef3 100644 --- a/internal/ingress/annotations/ipwhitelist/main.go +++ b/internal/ingress/annotations/ipwhitelist/main.go @@ -27,7 +27,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/annotations/parser" ing_errors "k8s.io/ingress-nginx/internal/ingress/errors" "k8s.io/ingress-nginx/internal/ingress/resolver" - "k8s.io/ingress-nginx/internal/sets" + "k8s.io/ingress-nginx/pkg/util/sets" ) // SourceRange returns the CIDR diff --git a/internal/ingress/annotations/ratelimit/main.go b/internal/ingress/annotations/ratelimit/main.go index 4011c25429..84a5f10f0d 100644 --- a/internal/ingress/annotations/ratelimit/main.go +++ b/internal/ingress/annotations/ratelimit/main.go @@ -26,7 +26,7 @@ import ( "k8s.io/ingress-nginx/internal/ingress/annotations/parser" "k8s.io/ingress-nginx/internal/ingress/resolver" "k8s.io/ingress-nginx/internal/net" - "k8s.io/ingress-nginx/internal/sets" + "k8s.io/ingress-nginx/pkg/util/sets" ) const ( diff --git a/internal/ingress/controller/nginx.go b/internal/ingress/controller/nginx.go index 41ec0445ad..05b3393f1a 100644 --- a/internal/ingress/controller/nginx.go +++ b/internal/ingress/controller/nginx.go @@ -44,6 +44,7 @@ import ( v1core "k8s.io/client-go/kubernetes/typed/core/v1" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/flowcontrol" + "k8s.io/ingress-nginx/pkg/tcpproxy" adm_controller "k8s.io/ingress-nginx/internal/admission/controller" "k8s.io/ingress-nginx/internal/ingress" @@ -58,7 +59,6 @@ import ( "k8s.io/ingress-nginx/internal/net/ssl" "k8s.io/ingress-nginx/internal/nginx" "k8s.io/ingress-nginx/internal/task" - "k8s.io/ingress-nginx/internal/watch" "k8s.io/ingress-nginx/pkg/util/file" klog "k8s.io/klog/v2" @@ -102,7 +102,7 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro runningConfig: new(ingress.Configuration), - Proxy: &TCPProxy{}, + Proxy: &tcpproxy.TCPProxy{}, metricCollector: mc, @@ -172,7 +172,7 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro n.t = ngxTpl - _, err = watch.NewFileWatcher(nginx.TemplatePath, onTemplateChange) + _, err = file.NewFileWatcher(nginx.TemplatePath, onTemplateChange) if err != nil { klog.Fatalf("Error creating file watcher for %v: %v", nginx.TemplatePath, err) } @@ -196,7 +196,7 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro } for _, f := range filesToWatch { - _, err = watch.NewFileWatcher(f, func() { + _, err = file.NewFileWatcher(f, func() { klog.InfoS("File changed detected. Reloading NGINX", "path", f) n.syncQueue.EnqueueTask(task.GetDummyObject("file-change")) }) @@ -242,7 +242,7 @@ type NGINXController struct { isShuttingDown bool - Proxy *TCPProxy + Proxy *tcpproxy.TCPProxy store store.Storer @@ -440,7 +440,7 @@ func (n NGINXController) DefaultEndpoint() ingress.Endpoint { func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressCfg ingress.Configuration) ([]byte, error) { if n.cfg.EnableSSLPassthrough { - servers := []*TCPServer{} + servers := []*tcpproxy.TCPServer{} for _, pb := range ingressCfg.PassthroughBackends { svc := pb.Service if svc == nil { @@ -465,7 +465,7 @@ func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressC } // TODO: Allow PassthroughBackends to specify they support proxy-protocol - servers = append(servers, &TCPServer{ + servers = append(servers, &tcpproxy.TCPServer{ Hostname: pb.Hostname, IP: svc.Spec.ClusterIP, Port: port, @@ -752,8 +752,8 @@ func (n *NGINXController) setupSSLProxy() { proxyPort := n.cfg.ListenPorts.SSLProxy klog.InfoS("Starting TLS proxy for SSL Passthrough") - n.Proxy = &TCPProxy{ - Default: &TCPServer{ + n.Proxy = &tcpproxy.TCPProxy{ + Default: &tcpproxy.TCPServer{ Hostname: "localhost", IP: "127.0.0.1", Port: proxyPort, diff --git a/internal/ingress/types_equals.go b/internal/ingress/types_equals.go index 3e39940a33..1ba80d07e5 100644 --- a/internal/ingress/types_equals.go +++ b/internal/ingress/types_equals.go @@ -17,7 +17,7 @@ limitations under the License. package ingress import ( - "k8s.io/ingress-nginx/internal/sets" + "k8s.io/ingress-nginx/pkg/util/sets" ) // Equal tests for equality between two Configuration types diff --git a/internal/net/ssl/ssl.go b/internal/net/ssl/ssl.go index 3397240955..bdbdb2e065 100644 --- a/internal/net/ssl/ssl.go +++ b/internal/net/ssl/ssl.go @@ -43,9 +43,8 @@ import ( "k8s.io/ingress-nginx/internal/ingress" ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config" - "k8s.io/ingress-nginx/internal/watch" - "k8s.io/ingress-nginx/pkg/util/file" + klog "k8s.io/klog/v2" ) @@ -509,8 +508,8 @@ func NewTLSListener(certificate, key string) *TLSListener { l.load() - _, _ = watch.NewFileWatcher(certificate, l.load) - _, _ = watch.NewFileWatcher(key, l.load) + _, _ = file.NewFileWatcher(certificate, l.load) + _, _ = file.NewFileWatcher(key, l.load) return &l } diff --git a/internal/ingress/controller/tcp.go b/pkg/tcpproxy/tcp.go similarity index 99% rename from internal/ingress/controller/tcp.go rename to pkg/tcpproxy/tcp.go index eedecc71ab..7bbff80b44 100644 --- a/internal/ingress/controller/tcp.go +++ b/pkg/tcpproxy/tcp.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package controller +package tcpproxy import ( "fmt" diff --git a/internal/watch/file_watcher.go b/pkg/util/file/file_watcher.go similarity index 99% rename from internal/watch/file_watcher.go rename to pkg/util/file/file_watcher.go index b393045b2b..eeb7b5721e 100644 --- a/internal/watch/file_watcher.go +++ b/pkg/util/file/file_watcher.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package watch +package file import ( "log" diff --git a/internal/watch/file_watcher_test.go b/pkg/util/file/file_watcher_test.go similarity index 96% rename from internal/watch/file_watcher_test.go rename to pkg/util/file/file_watcher_test.go index e1f5ed30dc..316cb6f1ef 100644 --- a/internal/watch/file_watcher_test.go +++ b/pkg/util/file/file_watcher_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package watch +package file import ( "os" @@ -22,8 +22,6 @@ import ( "path/filepath" "testing" "time" - - "k8s.io/ingress-nginx/pkg/util/file" ) func prepareTimeout() chan bool { @@ -61,7 +59,7 @@ func TestFileWatcher(t *testing.T) { t.Fatalf("expected no events before writing a file") case <-timeoutChan: } - os.WriteFile(f.Name(), []byte{}, file.ReadWriteByUser) + os.WriteFile(f.Name(), []byte{}, ReadWriteByUser) select { case <-events: case <-timeoutChan: diff --git a/internal/sets/match.go b/pkg/util/sets/match.go similarity index 100% rename from internal/sets/match.go rename to pkg/util/sets/match.go diff --git a/internal/sets/match_test.go b/pkg/util/sets/match_test.go similarity index 100% rename from internal/sets/match_test.go rename to pkg/util/sets/match_test.go