Skip to content

Commit

Permalink
(test) add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkashem committed Jul 19, 2019
1 parent 497ec34 commit c4056e6
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 1 deletion.
@@ -0,0 +1,96 @@
{{- if .Values.e2eLocalMode }}
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
creationTimestamp: "2019-07-08T17:25:44Z"
generation: 1
name: proxies.config.openshift.io
resourceVersion: "403"
selfLink: /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/proxies.config.openshift.io
uid: 6af86a13-a1a5-11e9-b519-0a2c4a2d8fc8
spec:
conversion:
strategy: None
group: config.openshift.io
names:
kind: Proxy
listKind: ProxyList
plural: proxies
singular: proxy
scope: Cluster
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: Spec holds user-settable values for the proxy configuration
properties:
httpProxy:
description: httpProxy is the URL of the proxy for HTTP requests. Empty
means unset and will not result in an env var.
type: string
httpsProxy:
description: httpsProxy is the URL of the proxy for HTTPS requests. Empty
means unset and will not result in an env var.
type: string
noProxy:
description: noProxy is a comma-separated list of hostnames and/or CIDRs
for which the proxy should not be used. Empty means unset and will
not result in an env var.
type: string
type: object
status:
description: status holds observed values from the cluster. They may not
be overridden.
properties:
httpProxy:
description: httpProxy is the URL of the proxy for HTTP requests.
type: string
httpsProxy:
description: httpsProxy is the URL of the proxy for HTTPS requests.
type: string
noProxy:
description: noProxy is a comma-separated list of hostnames and/or CIDRs
for which the proxy should not be used.
type: string
type: object
required:
- spec
version: v1
versions:
- name: v1
served: true
storage: true
status:
acceptedNames:
kind: Proxy
listKind: ProxyList
plural: proxies
singular: proxy
conditions:
- lastTransitionTime: "2019-07-08T17:25:44Z"
message: no conflicts found
reason: NoConflicts
status: "True"
type: NamesAccepted
- lastTransitionTime: null
message: the initial names have been accepted
reason: InitialNamesAccepted
status: "True"
type: Established
storedVersions:
- v1
{{- end }}
@@ -0,0 +1,10 @@
{{- if .Values.e2eLocalMode }}
apiVersion: config.openshift.io/v1
kind: Proxy
metadata:
name: cluster
spec:
httpProxy: "http://foo.com:8080"
httpsProxy: "https://foo.com:8080"
noProxy: "a,b,c"
{{- end }}
1 change: 1 addition & 0 deletions deploy/chart/values.yaml
Expand Up @@ -7,6 +7,7 @@ minKubeVersion: 1.11.0
writeStatusName: '""'
imagestream: false
debug: false
e2eLocalMode: false
installType: upstream
olm:
replicaCount: 1
Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e-values.yaml
@@ -1,5 +1,6 @@
writeStatusName: '""'
debug: true
e2eLocalMode: true

olm:
replicaCount: 1
Expand Down
154 changes: 153 additions & 1 deletion test/e2e/subscription_e2e_test.go
Expand Up @@ -17,7 +17,8 @@ import (
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"

"k8s.io/client-go/tools/clientcmd"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install"
Expand Down Expand Up @@ -406,6 +407,31 @@ func createSubscription(t *testing.T, crc versioned.Interface, namespace, name,
return buildSubscriptionCleanupFunc(t, crc, subscription)
}

func createSubscriptionWithPodConfig(t *testing.T, crc versioned.Interface, namespace, name, packageName, channel string, approval v1alpha1.Approval, config v1alpha1.SubscriptionConfig) cleanupFunc {
subscription := &v1alpha1.Subscription{
TypeMeta: metav1.TypeMeta{
Kind: v1alpha1.SubscriptionKind,
APIVersion: v1alpha1.SubscriptionCRDAPIVersion,
},
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: catalogSourceName,
CatalogSourceNamespace: namespace,
Package: packageName,
Channel: channel,
InstallPlanApproval: approval,
Config: config,
},
}

subscription, err := crc.OperatorsV1alpha1().Subscriptions(namespace).Create(subscription)
require.NoError(t, err)
return buildSubscriptionCleanupFunc(t, crc, subscription)
}

func createSubscriptionForCatalog(t *testing.T, crc versioned.Interface, namespace, name, catalog, packageName, channel, startingCSV string, approval v1alpha1.Approval) cleanupFunc {
subscription := &v1alpha1.Subscription{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -1089,6 +1115,132 @@ func TestSubscriptionInstallPlanStatus(t *testing.T) {
}
}

func TestCreateNewSubscriptionWithPodConfig(t *testing.T) {
defer cleaner.NotifyTestComplete(t, true)

newConfigClient := func(t *testing.T) configv1client.ConfigV1Interface {
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
// require.NoErrorf(t, err, "could not create rest config: %s", err.Error())
require.NoError(t, err,)

client, err := configv1client.NewForConfig(config)
// require.NoErrorf(t, err, "error creating OpenShift Config client: %s", err.Error())
require.NoError(t, err)

return client
}

proxyEnvVarFunc := func(t *testing.T, client configv1client.ConfigV1Interface) []corev1.EnvVar {
proxy, getErr := client.Proxies().Get("cluster", metav1.GetOptions{})
if getErr != nil {
if !k8serrors.IsNotFound(getErr) {
require.NoError(t, getErr)
}

return nil
}

require.NotNil(t, proxy)
proxyEnv := []corev1.EnvVar{
corev1.EnvVar{
Name: "HTTP_PROXY",
Value: proxy.Status.HTTPProxy,
},
corev1.EnvVar{
Name: "HTTPS_PROXY",
Value: proxy.Status.HTTPSProxy,
},
corev1.EnvVar{
Name: "NO_PROXY",
Value: proxy.Status.NoProxy,
},
}

return proxyEnv
}

c := newKubeClient(t)
crc := newCRClient(t)
config := newConfigClient(t)

defer func() {
require.NoError(t, crc.OperatorsV1alpha1().Subscriptions(testNamespace).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{}))
}()
require.NoError(t, initCatalog(t, c, crc))

podEnv := []corev1.EnvVar{
corev1.EnvVar{
Name: "MY_ENV_VARIABLE1",
Value: "value1",
},
corev1.EnvVar{
Name: "MY_ENV_VARIABLE2",
Value: "value2",
},
}
podConfig := v1alpha1.SubscriptionConfig{
Env: podEnv,
}

subscriptionName := "mysub-podconfig"
cleanup := createSubscriptionWithPodConfig(t, crc, testNamespace, subscriptionName, testPackageName, betaChannel, v1alpha1.ApprovalAutomatic, podConfig)
defer cleanup()

subscription, err := fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionStateAtLatestChecker)
require.NoError(t, err)
require.NotNil(t, subscription)

csv, err := fetchCSV(t, crc, subscription.Status.CurrentCSV, testNamespace, buildCSVConditionChecker(v1alpha1.CSVPhaseSucceeded))
require.NoError(t, err)

proxyEnv := proxyEnvVarFunc(t, config)
expected := podEnv
expected = append(expected, proxyEnv...)

checkDeploymentWithPodConfiguration(t, c, csv, podConfig.Env)
}

func checkDeploymentWithPodConfiguration(t *testing.T, client operatorclient.ClientInterface, csv *v1alpha1.ClusterServiceVersion, envVar []corev1.EnvVar) {
resolver := install.StrategyResolver{}

strategy, err := resolver.UnmarshalStrategy(csv.Spec.InstallStrategy)
require.NoError(t, err)

strategyDetailsDeployment, ok := strategy.(*install.StrategyDetailsDeployment)
require.Truef(t, ok, "could not cast install strategy as type %T", strategyDetailsDeployment)

find := func(envVar []corev1.EnvVar, name string) (env *corev1.EnvVar, found bool) {
for i := range envVar {
if name == envVar[i].Name {
found = true
env = &envVar[i]

break
}
}

return
}

check := func(container *corev1.Container) {
for _, e := range envVar {
existing, found := find(container.Env, e.Name)
require.Truef(t, found, "env variable name=%s not injected", e.Name)
require.NotNil(t, existing)
require.Equalf(t, e.Value, existing.Value, "env variable value does not match %s=%s", e.Name, e.Value)
}
}

for _, deploymentSpec := range strategyDetailsDeployment.DeploymentSpecs {
deployment, err := client.KubernetesInterface().AppsV1().Deployments(csv.GetNamespace()).Get(deploymentSpec.Name, metav1.GetOptions{})
require.NoError(t, err)

for i := range deployment.Spec.Template.Spec.Containers {
check(&deployment.Spec.Template.Spec.Containers[i])
}
}
}

func updateInternalCatalog(t *testing.T, c operatorclient.ClientInterface, crc versioned.Interface, catalogSourceName, namespace string, crds []apiextensions.CustomResourceDefinition, csvs []v1alpha1.ClusterServiceVersion, packages []registry.PackageManifest) {
fetchedInitialCatalog, err := fetchCatalogSource(t, crc, catalogSourceName, namespace, catalogSourceRegistryPodSynced)
require.NoError(t, err)
Expand Down

0 comments on commit c4056e6

Please sign in to comment.