diff --git a/controllers/gatewayclass_controller.go b/controllers/gatewayclass_controller.go index 6ebf926..6097067 100644 --- a/controllers/gatewayclass_controller.go +++ b/controllers/gatewayclass_controller.go @@ -84,12 +84,12 @@ func (r *GatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request // TODO: // 1.671457016981118e+09 DEBUG handling gatewayclass bigip {"controller": "gatewayclass", "controllerGroup": "gateway.networking.k8s.io", "controllerKind": "GatewayClass", "GatewayClass": {"name":"bigip"}, "namespace": "", "name": "bigip", "reconcileID": "bcd01fdd-8dfc-4be9-b3ab-c3d3a3fdb67e"} // 1.6714570170091689e+09 ERROR unable to update status {"controller": "gatewayclass", "controllerGroup": "gateway.networking.k8s.io", "controllerKind": "GatewayClass", "GatewayClass": {"name":"bigip"}, "namespace": "", "name": "bigip", "reconcileID": "bcd01fdd-8dfc-4be9-b3ab-c3d3a3fdb67e", "error": "Operation cannot be fulfilled on gatewayclasses.gateway.networking.k8s.io \"bigip\": the object has been modified; please apply your changes to the latest version and try again"} - if err := r.Status().Update(ctx, ngwc); err != nil { - slog.Errorf("unable to update status: %s", err.Error()) - return ctrl.Result{}, err - } else { - slog.Debugf("status updated") - } + // if err := r.Status().Update(ctx, ngwc); err != nil { + // slog.Errorf("unable to update status: %s", err.Error()) + // return ctrl.Result{}, err + // } else { + // slog.Debugf("status updated") + // } // upsert gatewayclass defer pkg.ActiveSIGs.SetGatewayClass(&obj) diff --git a/controllers/v1_controller.go b/controllers/v1_controller.go index 4259e84..19c5a24 100644 --- a/controllers/v1_controller.go +++ b/controllers/v1_controller.go @@ -69,6 +69,7 @@ func (r *NamespaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( slog := utils.LogFromContext(lctx) slog.Debugf("Namespace event: " + req.Name) + // TODO: update resource mappings since namespace labels are changed. if err := r.Get(ctx, req.NamespacedName, &obj); err != nil { if client.IgnoreNotFound(err) == nil { pkg.ActiveSIGs.UnsetNamespace(req.Name) diff --git a/deploy/2.install-kubernetes-gatewayapi-CRDs-v0.6.0.yaml b/deploy/2.install-kubernetes-gatewayapi-CRDs-v0.6.0.yaml index cb68d14..beb8e90 100644 --- a/deploy/2.install-kubernetes-gatewayapi-CRDs-v0.6.0.yaml +++ b/deploy/2.install-kubernetes-gatewayapi-CRDs-v0.6.0.yaml @@ -5035,7 +5035,7 @@ spec: containers: - name: webhook image: gcr.io/k8s-staging-gateway-api/admission-server:v0.6.0 - imagePullPolicy: Always + imagePullPolicy: IfNotPresent args: - -logtostderr - --tlsCertFile=/etc/certs/cert diff --git a/go.mod b/go.mod index 93bdab4..96ed8f9 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitee.com/zongzw/bigip-kubernetes-gateway go 1.19 require ( - gitee.com/zongzw/f5-bigip-rest v0.0.0-20230206042033-3ebe5fb7e08f + gitee.com/zongzw/f5-bigip-rest v0.0.0-20230213065231-bf76bccb90d2 github.com/google/uuid v1.3.0 github.com/onsi/ginkgo/v2 v2.6.0 github.com/onsi/gomega v1.24.1 diff --git a/go.sum b/go.sum index 77a3ba3..fe5615e 100644 --- a/go.sum +++ b/go.sum @@ -31,8 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -gitee.com/zongzw/f5-bigip-rest v0.0.0-20230206042033-3ebe5fb7e08f h1:G9bCWQDlOgFVEHuM/bQcFRwH/E8L1iC4HuxDEA8p2ZM= -gitee.com/zongzw/f5-bigip-rest v0.0.0-20230206042033-3ebe5fb7e08f/go.mod h1:jx0Y6qhir/J/75V5tCYrLlmKPaZUEfbCg8fS6Xo6Syw= +gitee.com/zongzw/f5-bigip-rest v0.0.0-20230213065231-bf76bccb90d2 h1:AAGcidjOi+GtY2A4QyVEU5U+TGk265cvvfaK4CKdZco= +gitee.com/zongzw/f5-bigip-rest v0.0.0-20230213065231-bf76bccb90d2/go.mod h1:jx0Y6qhir/J/75V5tCYrLlmKPaZUEfbCg8fS6Xo6Syw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/main.go b/main.go index bd1e826..bac4542 100644 --- a/main.go +++ b/main.go @@ -99,6 +99,7 @@ func main() { setupLog.Error(err, "failed to setup BIG-IPs") os.Exit(1) } + pkg.LogLevel = level ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, @@ -276,7 +277,7 @@ func setupBIGIPs(credsDir, confDir string) error { } url := fmt.Sprintf("https://%s:%d", c.Management.IpAddress, *c.Management.Port) username := c.Management.Username - bigip := f5_bigip.Initialize(url, username, pkg.BIPPassword, level) + bigip := f5_bigip.New(url, username, pkg.BIPPassword) pkg.BIGIPs = append(pkg.BIGIPs, bigip) bc := &f5_bigip.BIGIPContext{BIGIP: *bigip, Context: context.TODO()} diff --git a/pkg/cache.go b/pkg/cache.go index 96ef207..2107e71 100644 --- a/pkg/cache.go +++ b/pkg/cache.go @@ -382,36 +382,43 @@ func (c *SIGCache) _HTTPRoutesRefsOf(svc *v1.Service) []*gatewayv1beta1.HTTPRout return []*gatewayv1beta1.HTTPRoute{} } - refered := func(hr *gatewayv1beta1.HTTPRoute) bool { - for _, rl := range hr.Spec.Rules { - for _, br := range rl.BackendRefs { - ns := hr.Namespace - if br.Namespace != nil { - ns = string(*br.Namespace) - } - if utils.Keyname(ns, string(br.Name)) == utils.Keyname(svc.Namespace, svc.Name) { - return true - } - } - } - for _, rl := range hr.Spec.Rules { - for _, fl := range rl.Filters { - if fl.Type == gatewayv1beta1.HTTPRouteFilterExtensionRef && fl.ExtensionRef != nil { - er := fl.ExtensionRef - if er.Group == "" && er.Kind == "Service" { - if utils.Keyname(hr.Namespace, string(er.Name)) == utils.Keyname(svc.Namespace, svc.Name) { - return true - } - } - } - } - } - return false - } + // To performance perspective, it may be good. + // But the implementation is similiar to _attachedServices, would easily introduce issues. + // refered := func(hr *gatewayv1beta1.HTTPRoute) bool { + // for _, rl := range hr.Spec.Rules { + // for _, br := range rl.BackendRefs { + // ns := hr.Namespace + // if br.Namespace != nil { + // ns = string(*br.Namespace) + // } + // if utils.Keyname(ns, string(br.Name)) == utils.Keyname(svc.Namespace, svc.Name) { + // return true + // } + // } + // } + // for _, rl := range hr.Spec.Rules { + // for _, fl := range rl.Filters { + // if fl.Type == gatewayv1beta1.HTTPRouteFilterExtensionRef && fl.ExtensionRef != nil { + // er := fl.ExtensionRef + // if er.Group == "" && er.Kind == "Service" { + // if utils.Keyname(hr.Namespace, string(er.Name)) == utils.Keyname(svc.Namespace, svc.Name) { + // return true + // } + // } + // } + // } + // } + // return false + // } hrKeys := []string{} for _, hr := range c.HTTPRoute { - if refered(hr) { + svcs := c._attachedServices(hr) + svcKeys := []string{} + for _, s := range svcs { + svcKeys = append(svcKeys, utils.Keyname(s.Namespace, s.Name)) + } + if utils.Contains(svcKeys, utils.Keyname(svc.Namespace, svc.Name)) { hrKeys = append(hrKeys, utils.Keyname(hr.Namespace, hr.Name)) } } @@ -523,7 +530,7 @@ func (c *SIGCache) _canRefer(from, to client.Object) bool { func (c *SIGCache) syncCoreV1Resources(mgr manager.Manager) error { defer utils.TimeItToPrometheus()() - slog := utils.LogFromContext(context.TODO()) + slog := utils.LogFromContext(context.TODO()).WithLevel(LogLevel) kubeClient, err := kubernetes.NewForConfig(mgr.GetConfig()) if err != nil { return fmt.Errorf("unable to create kubeclient: %s", err.Error()) @@ -570,7 +577,7 @@ func (c *SIGCache) syncCoreV1Resources(mgr manager.Manager) error { func (c *SIGCache) syncGatewayResources(mgr manager.Manager) error { defer utils.TimeItToPrometheus()() - slog := utils.LogFromContext(context.TODO()) + slog := utils.LogFromContext(context.TODO()).WithLevel(LogLevel) checkAndWaitCacheStarted := func() error { var gtwList gatewayv1beta1.GatewayList diff --git a/pkg/parser.go b/pkg/parser.go index df55b83..96a113e 100644 --- a/pkg/parser.go +++ b/pkg/parser.go @@ -418,7 +418,7 @@ func parseiRulesFrom(className string, hr *gatewayv1beta1.HTTPRoute, rlt map[str %s %s set url $rscheme://$rhostname:$rport$ruri - log local0. "request redirect to $url" + # log local0. "request redirect to $url" HTTP::respond %d Location $url `, setScheme, setHostName, setUri, setPort, *rr.StatusCode)) } diff --git a/pkg/types.go b/pkg/types.go index 64ae6f0..582e75f 100644 --- a/pkg/types.go +++ b/pkg/types.go @@ -19,11 +19,6 @@ type DeployRequest struct { type CtxKeyType string -type ParseRequest struct { - Gateway *gatewayv1beta1.Gateway - HTTPRoute *gatewayv1beta1.HTTPRoute -} - type SIGCache struct { mutex sync.RWMutex SyncedAtStart bool diff --git a/pkg/vars.go b/pkg/vars.go index 0c786dd..e1b3f7c 100644 --- a/pkg/vars.go +++ b/pkg/vars.go @@ -9,6 +9,7 @@ var ( BIPConfigs BIGIPConfigs BIPPassword string refFromTo *ReferenceGrantFromTo + LogLevel string ) const (