Feat: upgrade istio from 1.19.5 to 1.27.1 (#3066)

This commit is contained in:
EndlessSeeker
2025-11-20 14:43:30 +08:00
committed by GitHub
parent 7dfc42fd92
commit b2b4f72775
173 changed files with 25684 additions and 4741 deletions

View File

@@ -12,50 +12,42 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// Updated based on Istio codebase by Higress
package istio
import (
"testing"
"time"
. "github.com/onsi/gomega"
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/config/memory"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pilot/pkg/networking/core/v1alpha3"
"istio.io/istio/pilot/pkg/serviceregistry/kube/controller"
"istio.io/istio/pilot/pkg/serviceregistry/util/xdsfake"
"istio.io/istio/pkg/config"
istioconst "istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/config/schema/collections"
"istio.io/istio/pkg/config/schema/gvk"
"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/kube/kclient/clienttest"
"istio.io/istio/pkg/test"
"istio.io/istio/pkg/util/sets"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
k8s "sigs.k8s.io/gateway-api/apis/v1alpha2"
k8s "sigs.k8s.io/gateway-api/apis/v1"
k8sbeta "sigs.k8s.io/gateway-api/apis/v1beta1"
"github.com/alibaba/higress/v2/pkg/config/constants"
higressconstant "github.com/alibaba/higress/v2/pkg/config/constants"
networking "istio.io/api/networking/v1alpha3"
"istio.io/istio/pilot/pkg/networking/core"
"istio.io/istio/pilot/pkg/serviceregistry/kube/controller"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/constants"
"istio.io/istio/pkg/config/schema/gvk"
"istio.io/istio/pkg/kube"
"istio.io/istio/pkg/kube/krt"
"istio.io/istio/pkg/test"
"istio.io/istio/pkg/test/util/assert"
)
var (
gatewayClassSpec = &k8s.GatewayClassSpec{
ControllerName: constants.ManagedGatewayController,
ControllerName: higressconstant.ManagedGatewayController,
}
gatewaySpec = &k8s.GatewaySpec{
GatewayClassName: "gwclass",
GatewayClassName: "higress",
Listeners: []k8s.Listener{
{
Name: "default",
Port: 9009,
Protocol: "HTTP",
AllowedRoutes: &k8s.AllowedRoutes{Namespaces: &k8s.RouteNamespaces{From: func() *k8s.FromNamespaces { x := k8sbeta.NamespacesFromAll; return &x }()}},
AllowedRoutes: &k8s.AllowedRoutes{Namespaces: &k8s.RouteNamespaces{From: func() *k8s.FromNamespaces { x := k8s.NamespacesFromAll; return &x }()}},
},
},
}
@@ -84,122 +76,62 @@ var AlwaysReady = func(class schema.GroupVersionResource, stop <-chan struct{})
return true
}
func setupController(t *testing.T, objs ...runtime.Object) *Controller {
kc := kube.NewFakeClient(objs...)
setupClientCRDs(t, kc)
stop := test.NewStop(t)
controller := NewController(
kc,
AlwaysReady,
controller.Options{KrtDebugger: krt.GlobalDebugHandler},
nil)
kc.RunAndWait(stop)
go controller.Run(stop)
cg := core.NewConfigGenTest(t, core.TestOptions{})
controller.Reconcile(cg.PushContext())
kube.WaitForCacheSync("test", stop, controller.HasSynced)
return controller
}
func TestListInvalidGroupVersionKind(t *testing.T) {
g := NewWithT(t)
clientSet := kube.NewFakeClient()
store := memory.NewController(memory.Make(collections.All))
controller := NewController(clientSet, store, AlwaysReady, nil, controller.Options{})
controller := setupController(t)
typ := config.GroupVersionKind{Kind: "wrong-kind"}
c := controller.List(typ, "ns1")
g.Expect(c).To(HaveLen(0))
assert.Equal(t, len(c), 0)
}
func TestListGatewayResourceType(t *testing.T) {
g := NewWithT(t)
clientSet := kube.NewFakeClient()
store := memory.NewController(memory.Make(collections.All))
controller := NewController(clientSet, store, AlwaysReady, nil, controller.Options{})
store.Create(config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.GatewayClass,
Name: "gwclass",
Namespace: "ns1",
controller := setupController(t,
&k8sbeta.GatewayClass{
ObjectMeta: metav1.ObjectMeta{
Name: "higress",
},
Spec: *gatewayClassSpec,
},
Spec: gatewayClassSpec,
})
if _, err := store.Create(config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.KubernetesGateway,
Name: "gwspec",
Namespace: "ns1",
&k8sbeta.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "gwspec",
Namespace: "ns1",
},
Spec: *gatewaySpec,
},
Spec: gatewaySpec,
}); err != nil {
t.Fatal(err)
}
store.Create(config.Config{
Meta: config.Meta{
GroupVersionKind: gvk.HTTPRoute,
Name: "http-route",
Namespace: "ns1",
},
Spec: httpRouteSpec,
})
cg := v1alpha3.NewConfigGenTest(t, v1alpha3.TestOptions{})
g.Expect(controller.Reconcile(cg.PushContext())).ToNot(HaveOccurred())
cfg := controller.List(gvk.Gateway, "ns1")
g.Expect(cfg).To(HaveLen(1))
for _, c := range cfg {
g.Expect(c.GroupVersionKind).To(Equal(gvk.Gateway))
g.Expect(c.Name).To(Equal("gwspec" + "-" + istioconst.KubernetesGatewayName + "-default"))
g.Expect(c.Namespace).To(Equal("ns1"))
g.Expect(c.Spec).To(Equal(expectedgw))
}
}
func TestNamespaceEvent(t *testing.T) {
clientSet := kube.NewFakeClient()
store := memory.NewController(memory.Make(collections.All))
c := NewController(clientSet, store, AlwaysReady, nil, controller.Options{})
s := xdsfake.NewFakeXDS()
c.RegisterEventHandler(gvk.Namespace, func(_, cfg config.Config, _ model.Event) {
s.ConfigUpdate(&model.PushRequest{
Full: true,
Reason: model.NewReasonStats(model.NamespaceUpdate),
&k8sbeta.HTTPRoute{
ObjectMeta: metav1.ObjectMeta{
Name: "http-route",
Namespace: "ns1",
},
Spec: *httpRouteSpec,
})
})
stop := test.NewStop(t)
c.Run(stop)
kube.WaitForCacheSync("test", stop, c.HasSynced)
c.state.ReferencedNamespaceKeys = sets.String{"allowed": struct{}{}}
ns1 := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{
Name: "ns1",
Labels: map[string]string{
"foo": "bar",
},
}}
ns2 := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{
Name: "ns2",
Labels: map[string]string{
"allowed": "true",
},
}}
ns := clienttest.Wrap(t, c.namespaces)
ns.Create(ns1)
s.AssertEmpty(t, time.Millisecond*10)
ns.Create(ns2)
s.AssertEmpty(t, time.Millisecond*10)
ns1.Annotations = map[string]string{"foo": "bar"}
ns.Update(ns1)
s.AssertEmpty(t, time.Millisecond*10)
ns2.Annotations = map[string]string{"foo": "bar"}
ns.Update(ns2)
s.AssertEmpty(t, time.Millisecond*10)
ns1.Labels["bar"] = "foo"
ns.Update(ns1)
s.AssertEmpty(t, time.Millisecond*10)
ns2.Labels["foo"] = "bar"
ns.Update(ns2)
s.WaitOrFail(t, "xds full")
ns1.Labels["allowed"] = "true"
ns.Update(ns1)
s.WaitOrFail(t, "xds full")
ns2.Labels["allowed"] = "false"
ns.Update(ns2)
s.WaitOrFail(t, "xds full")
dumpOnFailure(t, krt.GlobalDebugHandler)
cfg := controller.List(gvk.Gateway, "ns1")
assert.Equal(t, len(cfg), 1)
for _, c := range cfg {
assert.Equal(t, c.GroupVersionKind, gvk.Gateway)
assert.Equal(t, c.Name, "gwspec"+"-"+constants.KubernetesGatewayName+"-default")
assert.Equal(t, c.Namespace, "ns1")
assert.Equal(t, c.Spec, any(expectedgw))
}
}