Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
Cherry pick for release 0.12 to support KUBECONFIG in OLM (#299)
Browse files Browse the repository at this point in the history
* Support reading KubeConfig from KUBECONFIG env var (#293)

* Add upgrade tests into the e2e-tests-latest-serving (#286)

* Add upgrade tests into the e2e-tests-latest-serving

This PR adds the tests to verify the correct number and names of knative serving
deployments.

The test tag postupgrade is added, marking the tests to run after upgrade to the
latest HEAD of operator, with the latest generated manifest of knative serving.

* Install the latest release of the operator and then upgrade

* Split the long functions and rename the common package

* Refactor the PR based on the comments

* Update the library from jcrossley3/manifestival to manifestival

* Update pkg/reconciler/knativeserving/common/gateway.go

please fix

Co-Authored-By: Matt Moore <[email protected]>

Co-authored-by: Ali Ok <[email protected]>
Co-authored-by: Kenny Leung <[email protected]>
Co-authored-by: Matt Moore <[email protected]>
  • Loading branch information
4 people authored Feb 18, 2020
1 parent 855fd77 commit d3e3d2e
Show file tree
Hide file tree
Showing 27 changed files with 558 additions and 320 deletions.
24 changes: 12 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ required = [
version = "1.4.1"

[[constraint]]
name = "github.com/jcrossley3/manifestival"
name = "github.com/manifestival/manifestival"
branch = "client-go"

[[override]]
Expand Down
3 changes: 1 addition & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"flag"
"log"

"k8s.io/client-go/tools/clientcmd"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
"knative.dev/serving-operator/pkg/reconciler/knativeserving"
Expand All @@ -28,7 +27,7 @@ import (
func main() {
flag.Parse()

cfg, err := clientcmd.BuildConfigFromFlags(*knativeserving.MasterURL, *knativeserving.Kubeconfig)
cfg, err := sharedmain.GetConfig(*knativeserving.MasterURL, *knativeserving.Kubeconfig)
if err != nil {
log.Fatal("Error building kubeconfig", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/knativeserving/common/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package common
import (
"fmt"

mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/knativeserving/common/config_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
package common

import (
mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
servingv1alpha1 "knative.dev/serving-operator/pkg/apis/serving/v1alpha1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/knativeserving/common/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.
package common

import (
mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"
servingv1alpha1 "knative.dev/serving-operator/pkg/apis/serving/v1alpha1"
Expand Down
18 changes: 17 additions & 1 deletion pkg/reconciler/knativeserving/common/gateway.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package common

import (
mf "github.com/jcrossley3/manifestival"
/*
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
servingv1alpha1 "knative.dev/serving-operator/pkg/apis/serving/v1alpha1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/knativeserving/common/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package common
import (
"strings"

mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/knativeserving/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ package knativeserving
import (
"context"
"flag"
"knative.dev/pkg/injection/sharedmain"
"os"
"path/filepath"

"github.com/go-logr/zapr"
mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/clientcmd"
deploymentinformer "knative.dev/pkg/client/injection/kube/informers/apps/v1/deployment"
"knative.dev/pkg/configmap"
"knative.dev/pkg/controller"
Expand Down Expand Up @@ -60,7 +60,7 @@ func NewController(

koDataDir := os.Getenv("KO_DATA_PATH")

cfg, err := clientcmd.BuildConfigFromFlags(*MasterURL, *Kubeconfig)
cfg, err := sharedmain.GetConfig(*MasterURL, *Kubeconfig)
if err != nil {
c.Logger.Error(err, "Error building kubeconfig")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/knativeserving/knativeserving_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"context"
"fmt"

mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"go.uber.org/zap"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/knativeserving/minikube/minikube.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"go.uber.org/zap"
"k8s.io/client-go/kubernetes"

mf "github.com/jcrossley3/manifestival"
mf "github.com/manifestival/manifestival"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/e2e.go → test/client/setup.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019 The Knative Authors
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e
package client

import (
"testing"
Expand All @@ -20,6 +20,7 @@ import (
// Apparently just importing it is enough. @_@ side effects @_@.
// https://github.com/kubernetes/client-go/issues/242
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

pkgTest "knative.dev/pkg/test"
"knative.dev/serving-operator/test"
)
Expand Down
26 changes: 11 additions & 15 deletions test/e2e-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ source $(dirname $0)/../vendor/knative.dev/test-infra/scripts/e2e-tests.sh
# Latest serving release. This is intentionally hardcoded for now, but
# will need the ability to test against the latest successful serving
# CI runs in the future.
readonly LATEST_SERVING_RELEASE_VERSION=0.6.0
readonly LATEST_SERVING_RELEASE_VERSION=$(git describe --match "v[0-9]*" --abbrev=0)
# Istio version we test with
readonly ISTIO_VERSION=1.1.3
readonly ISTIO_VERSION="1.4.2"
# Test without Istio mesh enabled
readonly ISTIO_MESH=0
# Namespace used for tests
Expand All @@ -43,23 +43,16 @@ function istio_yaml() {
local istio_mesh=$2
local suffix=""
if [[ $istio_mesh -eq 0 ]]; then
suffix="-lean"
suffix="ci-no-mesh"
else
suffix="ci-mesh"
fi
echo "third_party/istio-${istio_version}/istio${suffix}.yaml"
echo "third_party/istio-${istio_version}/istio-${suffix}.yaml"
}

# Install Istio.
function install_istio() {
local base_url="https://raw.githubusercontent.com/knative/serving/v${LATEST_SERVING_RELEASE_VERSION}"
# Decide the Istio configuration to install.
if [[ -z "$ISTIO_VERSION" ]]; then
# Defaults to 1.1-latest
ISTIO_VERSION=1.1-latest
fi
if [[ -z "$ISTIO_MESH" ]]; then
# Defaults to using mesh.
ISTIO_MESH=1
fi
local base_url="https://raw.githubusercontent.com/knative/serving/${LATEST_SERVING_RELEASE_VERSION}"
INSTALL_ISTIO_CRD_YAML="${base_url}/$(istio_crds_yaml $ISTIO_VERSION)"
INSTALL_ISTIO_YAML="${base_url}/$(istio_yaml $ISTIO_VERSION $ISTIO_MESH)"

Expand All @@ -76,10 +69,13 @@ function install_istio() {
kubectl apply -f "${INSTALL_ISTIO_YAML}" || return 1
}

function install_serving_operator() {
function create_namespace() {
echo ">> Creating test namespaces"
# All the custom resources and Knative Serving resources are created under this TEST_NAMESPACE.
kubectl create namespace $TEST_NAMESPACE
}

function install_serving_operator() {
header "Installing Knative Serving operator"
# Deploy the operator
ko apply -f config/
Expand Down
1 change: 1 addition & 0 deletions test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ source $(dirname $0)/e2e-common.sh

function knative_setup() {
install_istio || fail_test "Istio installation failed"
create_namespace
install_serving_operator
}

Expand Down
49 changes: 46 additions & 3 deletions test/e2e-tests-latest-serving.sh → test/e2e-upgrade-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,47 @@ source $(dirname $0)/e2e-common.sh
OPERATOR_DIR=$(dirname $0)/..
KNATIVE_SERVING_DIR=${OPERATOR_DIR}/..

function knative_setup() {
function install_latest_operator_release() {
header "Installing Knative Serving operator latest public release"
local full_url="https://github.com/knative/serving-operator/releases/download/${LATEST_SERVING_RELEASE_VERSION}/serving-operator.yaml"

local release_yaml="$(mktemp)"
wget "${full_url}" -O "${release_yaml}" \
|| fail_test "Unable to download latest Knative Serving Operator release."

install_istio || fail_test "Istio installation failed"
kubectl apply -f "${release_yaml}" || fail_test "Knative Serving Operator latest release installation failed"
create_custom_resource
wait_until_pods_running ${TEST_NAMESPACE}
}

function create_custom_resource() {
echo ">> Creating the custom resource of Knative Serving:"
cat <<EOF | kubectl apply -f -
apiVersion: operator.knative.dev/v1alpha1
kind: KnativeServing
metadata:
name: knative-serving
namespace: ${TEST_NAMESPACE}
spec:
config:
defaults:
revision-timeout-seconds: "300" # 5 minutes
autoscaler:
stable-window: "60s"
deployment:
registriesSkippingTagResolving: "ko.local,dev.local"
logging:
loglevel.controller: "debug"
EOF
}

function knative_setup() {
create_namespace
install_latest_operator_release
}

function install_head() {
generate_latest_serving_manifest
install_serving_operator
}
Expand Down Expand Up @@ -74,12 +113,16 @@ function generate_latest_serving_manifest() {
# Skip installing istio as an add-on
initialize $@ --skip-istio-addon

TIMEOUT=20m

install_head

# If we got this far, the operator installed Knative Serving of the latest source code.
header "Running tests for Knative Serving Operator"
failed=0

# Run the integration tests
go_test_e2e -timeout=20m ./test/e2e || failed=1
# Run the postupgrade tests
go_test_e2e -tags=postupgrade -timeout=${TIMEOUT} ./test/upgrade || failed=1

# Require that tests succeeded.
(( failed )) && fail_test
Expand Down
Loading

0 comments on commit d3e3d2e

Please sign in to comment.