Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move utils to better locations to help in decoupling #8853

Merged
merged 2 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/ingress/annotations/authreq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/annotations/globalratelimit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/annotations/ipwhitelist/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/annotations/ratelimit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
18 changes: 9 additions & 9 deletions internal/ingress/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -102,7 +102,7 @@ func NewNGINXController(config *Configuration, mc metric.Collector) *NGINXContro

runningConfig: new(ingress.Configuration),

Proxy: &TCPProxy{},
Proxy: &tcpproxy.TCPProxy{},

metricCollector: mc,

Expand Down Expand Up @@ -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)
}
Expand All @@ -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"))
})
Expand Down Expand Up @@ -242,7 +242,7 @@ type NGINXController struct {

isShuttingDown bool

Proxy *TCPProxy
Proxy *tcpproxy.TCPProxy

store store.Storer

Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/types_equals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions internal/net/ssl/ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/controller/tcp.go → pkg/tcpproxy/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package controller
package tcpproxy

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package watch
package file

import (
"log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package watch
package file

import (
"os"
"path"
"path/filepath"
"testing"
"time"

"k8s.io/ingress-nginx/pkg/util/file"
)

func prepareTimeout() chan bool {
Expand Down Expand Up @@ -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:
Expand Down
File renamed without changes.
File renamed without changes.