diff --git a/pkg/apis/gatewayapi/v1alpha2/register.go b/pkg/apis/gatewayapi/v1alpha2/register.go index 15a84494..099d7b27 100644 --- a/pkg/apis/gatewayapi/v1alpha2/register.go +++ b/pkg/apis/gatewayapi/v1alpha2/register.go @@ -7,17 +7,25 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) -// SchemeGroupVersion is the GroupVersion for the Kuma API +// SchemeGroupVersion is the identifier for the API which includes +// the name of the group and the version of the API var SchemeGroupVersion = schema.GroupVersion{Group: gatewayapi.GroupName, Version: "v1alpha2"} -// Resource gets a Kuma GroupResource for a specified resource +// Resource takes an unqualified resource and returns a Group qualified GroupResource func Resource(resource string) schema.GroupResource { return SchemeGroupVersion.WithResource(resource).GroupResource() } var ( + // SchemeBuilder collects functions that add things to a scheme. It's to allow + // code to compile without explicitly referencing generated types. You should + // declare one in each package that will have generated deep copy or conversion + // functions. SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) - AddToScheme = SchemeBuilder.AddToScheme + + // AddToScheme applies all the stored functions to the scheme. A non-nil error + // indicates that one function failed and the attempt was abandoned. + AddToScheme = SchemeBuilder.AddToScheme ) // Adds the list of known types to Scheme. diff --git a/pkg/metrics/observers/factory.go b/pkg/metrics/observers/factory.go index af699919..917bc9ab 100644 --- a/pkg/metrics/observers/factory.go +++ b/pkg/metrics/observers/factory.go @@ -68,7 +68,7 @@ func (factory Factory) Observer(provider string) Interface { return &NginxObserver{ client: factory.Client, } - case provider == flaggerv1.KubernetesProvider || provider == flaggerv1.GatewayAPIProvider: + case provider == flaggerv1.KubernetesProvider || strings.HasPrefix(provider, flaggerv1.GatewayAPIProvider): return &HttpObserver{ client: factory.Client, } diff --git a/pkg/router/gateway_api.go b/pkg/router/gateway_api.go index a3b22b9e..39220ac3 100644 --- a/pkg/router/gateway_api.go +++ b/pkg/router/gateway_api.go @@ -164,20 +164,23 @@ func (gwr *GatewayAPIRouter) Reconcile(canary *flaggerv1.Canary) error { return fmt.Errorf("HTTPRoute %s.%s get error: %w", apexSvcName, hrNamespace, err) } - if diff := cmp.Diff( - httpRoute.Spec, httpRouteSpec, - cmpopts.IgnoreFields(v1alpha2.BackendRef{}, "Weight"), - ); diff != "" { - hrClone := httpRoute.DeepCopy() - hrClone.Spec = httpRouteSpec - _, err := gwr.gatewayAPIClient.GatewayapiV1alpha2().HTTPRoutes(hrNamespace). - Update(context.TODO(), hrClone, metav1.UpdateOptions{}) - if err != nil { - return fmt.Errorf("HTTPRoute %s.%s update error: %w", hrClone.GetName(), hrNamespace, err) + if httpRoute != nil { + if diff := cmp.Diff( + httpRoute.Spec, httpRouteSpec, + cmpopts.IgnoreFields(v1alpha2.BackendRef{}, "Weight"), + ); diff != "" { + hrClone := httpRoute.DeepCopy() + hrClone.Spec = httpRouteSpec + _, err := gwr.gatewayAPIClient.GatewayapiV1alpha2().HTTPRoutes(hrNamespace). + Update(context.TODO(), hrClone, metav1.UpdateOptions{}) + if err != nil { + return fmt.Errorf("HTTPRoute %s.%s update error: %w", hrClone.GetName(), hrNamespace, err) + } + gwr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). + Infof("HTTPProxy %s.%s updated", hrClone.GetName(), hrNamespace) } - gwr.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)). - Infof("HTTPProxy %s.%s updated", hrClone.GetName(), hrNamespace) } + return nil } diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index db825180..0561b40b 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -66,7 +66,6 @@ func newFixture(c *flaggerv1.Canary) fixture { newTestDeployment(), newTestABTestDeployment(), newTestIngress(), - newTestGateway(), ) meshClient := fakeFlagger.NewSimpleClientset() @@ -529,25 +528,3 @@ func newTestGatewayAPICanary() *flaggerv1.Canary { } return cd } - -func newTestGateway() *v1alpha2.Gateway { - hostName := v1alpha2.Hostname("app.example.com") - gw := &v1alpha2.Gateway{ - TypeMeta: metav1.TypeMeta{APIVersion: v1alpha2.SchemeGroupVersion.String()}, - ObjectMeta: metav1.ObjectMeta{ - Namespace: "default", - Name: "podinfo", - }, - Spec: v1alpha2.GatewaySpec{ - GatewayClassName: "example", - Listeners: []v1alpha2.Listener{ - { - Hostname: &hostName, - Name: "http", - Port: 80, - }, - }, - }, - } - return gw -} diff --git a/test/gatewayapi/install.sh b/test/gatewayapi/install.sh index ad8391a8..0aa71d3b 100755 --- a/test/gatewayapi/install.sh +++ b/test/gatewayapi/install.sh @@ -8,6 +8,9 @@ REPO_ROOT=$(git rev-parse --show-toplevel) KUSTOMIZE_VERSION=4.5.2 OS=$(uname -s) ARCH=$(arch) +if [[ $ARCH == "x86_64" ]]; then + ARCH="amd64" +fi mkdir -p ${REPO_ROOT}/bin @@ -22,9 +25,9 @@ kubectl -n projectcontour rollout status deployment/contour kubectl -n projectcontour get all echo '>>> Installing Kustomize' -cd ${REPO_ROOT}/bin && kustomize_url=https://github.com/kubernetes-sigs/kustomize/releases/download && \ -curl -sL ${kustomize_url}/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_${OS}_${ARCH}.tar.gz | \ -tar xz +cd ${REPO_ROOT}/bin && \ + curl -sL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_${OS}_${ARCH}.tar.gz | \ + tar xz echo '>>> Installing Flagger' ${REPO_ROOT}/bin/kustomize build ${REPO_ROOT}/test/gatewayapi | kubectl apply -f - diff --git a/test/gatewayapi/run.sh b/test/gatewayapi/run.sh index 519424be..67153fa9 100755 --- a/test/gatewayapi/run.sh +++ b/test/gatewayapi/run.sh @@ -8,4 +8,4 @@ DIR="$(cd "$(dirname "$0")" && pwd)" "$DIR"/install.sh "$REPO_ROOT"/test/workloads/init.sh -"$DIR"/run-canary.sh +"$DIR"/test-canary.sh