Skip to content

Commit

Permalink
Merge pull request operator-framework#348 from ecordell/subscription-…
Browse files Browse the repository at this point in the history
…approvalmode

Add installPlanApproval to Subscription-v1
  • Loading branch information
ecordell authored May 12, 2018
2 parents 0bf75ce + 2e290a8 commit f2a2583
Show file tree
Hide file tree
Showing 16 changed files with 305 additions and 107 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ run-local-shift: rc

e2e-local: values_file = test/e2e/e2e-values.yaml
e2e-local: rc
./scripts/build_local.sh
./scripts/run_e2e_local.sh
. ./scripts/build_local.sh
. ./scripts/run_e2e_local.sh

e2e-local-shift: values_file = test/e2e/e2e-values.yaml
e2e-local-shift: rc
./scripts/build_local_shift.sh
./scripts/run_e2e_local.sh
. ./scripts/build_local_shift.sh
. ./scripts/run_e2e_local.sh

e2e-local-docker: values_file = test/e2e/e2e-values.yaml
e2e-local-docker: rc
./scripts/build_local.sh
./scripts/run_e2e_docker.sh
. ./scripts/build_local.sh
. ./scripts/run_e2e_docker.sh

DEP := $(GOPATH)/bin/dep
$(DEP):
Expand Down
13 changes: 0 additions & 13 deletions e2e-local-build.Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion e2e-local-run.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ RUN apt-get update
RUN apt-get install -y jq
COPY pkg pkg
COPY vendor vendor
COPY e2e e2e
COPY test/e2e test/e2e
RUN go test -c -o /bin/e2e ./test/e2e/...
CMD ["./test/e2e/e2e.sh"]
40 changes: 40 additions & 0 deletions e2e.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
FROM golang:1.10 as builder
LABEL builder=true
WORKDIR /go/src/github.com/operator-framework/operator-lifecycle-manager
RUN curl -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -o /bin/jq
RUN chmod +x /bin/jq
COPY . .
RUN make build-coverage
RUN go test -c -o /bin/e2e ./test/e2e/...

FROM alpine:latest as olm
LABEL olm=true
WORKDIR /
COPY --from=builder /go/src/github.com/operator-framework/operator-lifecycle-manager/bin/alm /bin/alm
EXPOSE 8080
CMD ["/bin/alm"]

FROM alpine:latest as catalog
LABEL catalog=true
WORKDIR /
COPY --from=builder /go/src/github.com/operator-framework/operator-lifecycle-manager/bin/catalog /bin/catalog
EXPOSE 8080
CMD ["/bin/catalog"]

FROM alpine:latest as broker
LABEL broker=true
WORKDIR /
COPY --from=builder /go/src/github.com/operator-framework/operator-lifecycle-manager/bin/servicebroker /bin/servicebroker
EXPOSE 8080
EXPOSE 8005
CMD ["/bin/servicebroker"]

FROM golang:1.10
LABEL e2e=true
RUN mkdir -p /var/e2e
WORKDIR /var/e2e
COPY --from=builder /bin/e2e /bin/e2e
COPY --from=builder /bin/jq /bin/jq
COPY ./test/e2e/e2e.sh /var/e2e/e2e.sh
COPY ./test/e2e/tap.jq /var/e2e/tap.jq
CMD ["/bin/e2e"]
5 changes: 2 additions & 3 deletions pkg/api/apis/installplan/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ const (
type Approval string

const (
ApprovalAutomatic Approval = "Automatic"
ApprovalUpdateOnly Approval = "Update-Only"
ApprovalManual Approval = "Manual"
ApprovalAutomatic Approval = "Automatic"
ApprovalManual Approval = "Manual"
)

// InstallPlanSpec defines a set of Application resources to be installed
Expand Down
19 changes: 14 additions & 5 deletions pkg/api/apis/subscription/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v1alpha1

import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/installplan/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand All @@ -25,11 +26,11 @@ const (

// SubscriptionSpec defines an Application that can be installed
type SubscriptionSpec struct {
CatalogSource string `json:"source"`
Package string `json:"name"`
Channel string `json:"channel,omitempty"`

StartingCSV string `json:"startingCSV,omitempty"`
CatalogSource string `json:"source"`
Package string `json:"name"`
Channel string `json:"channel,omitempty"`
StartingCSV string `json:"startingCSV,omitempty"`
InstallPlanApproval v1alpha1.Approval `json:"installPlanApproval,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -64,3 +65,11 @@ type SubscriptionList struct {

Items []Subscription `json:"items"`
}

// GetInstallPlanApproval gets the configured install plan approval or the default
func (s *Subscription) GetInstallPlanApproval() v1alpha1.Approval {
if s.Spec.InstallPlanApproval == v1alpha1.ApprovalManual {
return v1alpha1.ApprovalManual
}
return v1alpha1.ApprovalAutomatic
}
2 changes: 1 addition & 1 deletion pkg/controller/operators/catalog/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (o *Operator) syncSubscription(sub *v1alpha1.Subscription) (*v1alpha1.Subsc
ObjectMeta: metav1.ObjectMeta{},
Spec: ipv1alpha1.InstallPlanSpec{
ClusterServiceVersionNames: []string{sub.Status.CurrentCSV},
Approval: ipv1alpha1.ApprovalAutomatic,
Approval: sub.GetInstallPlanApproval(),
},
}
owner := []metav1.OwnerReference{
Expand Down
77 changes: 77 additions & 0 deletions pkg/controller/operators/catalog/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,83 @@ func TestSyncSubscription(t *testing.T) {
err: "",
},
},
{
name: "no csv or installplan",
subName: "creates installplan successfully with manual approval",
initial: initial{
catalogName: "flying-unicorns",
getCSVResult: nil,
createInstallPlanResult: &ipv1alpha1.InstallPlan{
ObjectMeta: metav1.ObjectMeta{
Name: "installplan-1",
UID: types.UID("UID-OK"),
},
},
createInstallPlanError: nil,
},
args: args{subscription: &v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Namespace: "fairy-land",
Name: "test-subscription",
UID: types.UID("subscription-uid"),
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: "flying-unicorns",
Package: "rainbows",
Channel: "magical",
InstallPlanApproval: ipv1alpha1.ApprovalManual,
},
Status: v1alpha1.SubscriptionStatus{
CurrentCSV: "latest-and-greatest",
Install: nil,
},
}},
expected: expected{
installPlan: &ipv1alpha1.InstallPlan{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "install-latest-and-greatest-",
Namespace: "fairy-land",
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "app.coreos.com/v1alpha1",
Kind: "Subscription-v1",
Name: "test-subscription",
UID: types.UID("subscription-uid"),
},
},
},
Spec: ipv1alpha1.InstallPlanSpec{
ClusterServiceVersionNames: []string{"latest-and-greatest"},
Approval: ipv1alpha1.ApprovalManual,
},
},
subscription: &v1alpha1.Subscription{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{PackageLabel: "rainbows", CatalogLabel: "flying-unicorns", ChannelLabel: "magical"},
Namespace: "fairy-land",
Name: "test-subscription",
UID: types.UID("subscription-uid"),
},
Spec: &v1alpha1.SubscriptionSpec{
CatalogSource: "flying-unicorns",
Package: "rainbows",
Channel: "magical",
InstallPlanApproval: ipv1alpha1.ApprovalManual,
},
Status: v1alpha1.SubscriptionStatus{
CurrentCSV: "latest-and-greatest",
Install: &v1alpha1.InstallPlanReference{
UID: types.UID("UID-OK"),
Name: "installplan-1",
},
State: v1alpha1.SubscriptionStateUpgradePending,
},
},
csvName: "latest-and-greatest",
namespace: "fairy-land",
err: "",
},
},
{
name: "no csv or installplan",
subName: "installplan error",
Expand Down
10 changes: 5 additions & 5 deletions scripts/build_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ set -e
minikube start --extra-config=apiserver.Authorization.Mode=RBAC || { echo 'Cannot start minikube.'; exit 1; }
eval $(minikube docker-env) || { echo 'Cannot switch to minikube docker'; exit 1; }
kubectl config use-context minikube
docker build \
-t quay.io/coreos/catalog:local \
-t quay.io/coreos/olm:local \
-t quay.io/coreos/olm-service-broker:local \
-f e2e-local-build.Dockerfile .
docker build -f e2e.Dockerfile .
docker tag $(docker images --filter 'label=broker=true' --format '{{.CreatedAt}}\t{{.ID}}' | sort -nr | head -n 1 | cut -f2) quay.io/coreos/olm-service-broker:local
docker tag $(docker images --filter 'label=catalog=true' --format '{{.CreatedAt}}\t{{.ID}}' | sort -nr | head -n 1 | cut -f2) quay.io/coreos/catalog:local
docker tag $(docker images --filter 'label=e2e=true' --format '{{.CreatedAt}}\t{{.ID}}' | sort -nr | head -n 1 | cut -f2) quay.io/coreos/olm-e2e:local
docker tag $(docker images --filter 'label=olm=true' --format '{{.CreatedAt}}\t{{.ID}}' | sort -nr | head -n 1 | cut -f2) quay.io/coreos/olm:local
14 changes: 2 additions & 12 deletions scripts/run_e2e_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,10 @@ trap cleanupAndExit SIGINT SIGTERM EXIT
./scripts/install_local.sh ${namespace} test/e2e/resources

mkdir -p test/e2e/test-resources

pushd test/e2e/chart/templates
filenames=$(ls *.yaml)
popd

for f in ${filenames}
do
echo "Processing $f file..."
helm template --set namespace=${namespace} -f test/e2e/e2e-values.yaml -x templates/${f} test/e2e/chart > test/e2e/test-resources/${f}
done
helm template --set namespace=${namespace} -f test/e2e/e2e-values.yaml test/e2e/chart --output-dir test/e2e/test-resources

eval $(minikube docker-env) || { echo 'Cannot switch to minikube docker'; exit 1; }
docker build --no-cache -t quay.io/coreos/alm-e2e:local -f e2e-local-run.Dockerfile .
kubectl apply -f test/e2e/test-resources
kubectl apply -f test/e2e/test-resources/alm-e2e/templates
until kubectl -n ${namespace} logs job/e2e | grep -v "ContainerCreating"; do echo "waiting for job to run" && sleep 1; done
kubectl -n ${namespace} logs job/e2e -f

Expand Down
1 change: 0 additions & 1 deletion scripts/run_e2e_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,5 @@ trap cleanupAndExit SIGINT SIGTERM EXIT

./scripts/install_local.sh ${namespace} test/e2e/resources


# run tests
KUBECONFIG=~/.kube/config NAMESPACE=${namespace} go test -v ./test/e2e/... ${1/[[:alnum:]-]*/-run ${1}}
41 changes: 21 additions & 20 deletions test/e2e/csv_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,26 @@ type cleanupFunc func()

var immediateDeleteGracePeriod int64 = 0

func buildCSVCleanupFunc(c opClient.Interface, csv v1alpha1.ClusterServiceVersion) cleanupFunc {
func buildCSVCleanupFunc(t *testing.T, c opClient.Interface, csv v1alpha1.ClusterServiceVersion, deleteCRDs bool) cleanupFunc {
return func() {
err := c.DeleteCustomResource(apis.GroupName, v1alpha1.GroupVersion, testNamespace, v1alpha1.ClusterServiceVersionKind, csv.GetName())
if err != nil {
fmt.Println(err)
require.NoError(t, c.DeleteCustomResource(apis.GroupName, v1alpha1.GroupVersion, testNamespace, v1alpha1.ClusterServiceVersionKind, csv.GetName()))
if deleteCRDs {
for _, crd := range csv.Spec.CustomResourceDefinitions.Owned {
require.NoError(t, c.DeleteCustomResourceDefinition(crd.Name, &metav1.DeleteOptions{}))
}
}
}
}

func createCSV(c opClient.Interface, csv v1alpha1.ClusterServiceVersion) (cleanupFunc, error) {
func createCSV(t *testing.T, c opClient.Interface, csv v1alpha1.ClusterServiceVersion, cleanupCRDs bool) (cleanupFunc, error) {
csv.Kind = v1alpha1.ClusterServiceVersionKind
csv.APIVersion = v1alpha1.SchemeGroupVersion.String()
csv.Namespace = testNamespace
csvUnst, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&csv)
if err != nil {
return nil, err
}
require.NoError(t, err)
err = c.CreateCustomResource(&unstructured.Unstructured{Object: csvUnst})
if err != nil {
return nil, err
}
return buildCSVCleanupFunc(c, csv), nil
require.NoError(t, err)
return buildCSVCleanupFunc(t, c, csv, cleanupCRDs), nil

}

Expand Down Expand Up @@ -139,11 +137,14 @@ func fetchCSV(t *testing.T, c opClient.Interface, name string, checker csvCondit

func waitForDeploymentToDelete(t *testing.T, c opClient.Interface, name string) error {
return wait.Poll(pollInterval, pollDuration, func() (bool, error) {
t.Logf("waiting for deployment %s to delete", name)
_, err := c.GetDeployment(testNamespace, name)
if errors.IsNotFound(err) {
t.Logf("deleted %s", name)
return true, nil
}
if err != nil {
t.Logf("err trying to delete %s: %s", name, err)
return false, err
}
return false, nil
Expand Down Expand Up @@ -213,7 +214,7 @@ func TestCreateCSVWithUnmetRequirements(t *testing.T) {
},
}

cleanupCSV, err := createCSV(c, csv)
cleanupCSV, err := createCSV(t, c, csv, false)
require.NoError(t, err)
defer cleanupCSV()

Expand Down Expand Up @@ -290,7 +291,7 @@ func TestCreateCSVRequirementsMet(t *testing.T) {
require.NoError(t, err)
defer cleanupCRD()

cleanupCSV, err := createCSV(c, csv)
cleanupCSV, err := createCSV(t, c, csv, true)
require.NoError(t, err)
defer cleanupCSV()

Expand Down Expand Up @@ -388,9 +389,9 @@ func TestUpdateCSVSameDeploymentName(t *testing.T) {
require.NoError(t, err)
defer cleanupCRD()

cleanupCSV, err := createCSV(c, csv)
// don't need to cleanup this CSV, it will be deleted by the upgrade process
_, err = createCSV(t, c, csv, true)
require.NoError(t, err)
defer cleanupCSV()

// Wait for current CSV to succeed
_, err = fetchCSV(t, c, csv.Name, csvSucceededChecker)
Expand Down Expand Up @@ -465,7 +466,7 @@ func TestUpdateCSVSameDeploymentName(t *testing.T) {
},
}

cleanupNewCSV, err := createCSV(c, csvNew)
cleanupNewCSV, err := createCSV(t, c, csvNew, true)
require.NoError(t, err)
defer cleanupNewCSV()

Expand Down Expand Up @@ -562,9 +563,9 @@ func TestUpdateCSVDifferentDeploymentName(t *testing.T) {
require.NoError(t, err)
defer cleanupCRD()

cleanupCSV, err := createCSV(c, csv)
// don't need to clean up this CSV, it will be deleted by the upgrade process
_, err = createCSV(t, c, csv, true)
require.NoError(t, err)
defer cleanupCSV()

// Wait for current CSV to succeed
_, err = fetchCSV(t, c, csv.Name, csvSucceededChecker)
Expand Down Expand Up @@ -615,7 +616,7 @@ func TestUpdateCSVDifferentDeploymentName(t *testing.T) {
},
}

cleanupNewCSV, err := createCSV(c, csvNew)
cleanupNewCSV, err := createCSV(t, c, csvNew, true)
require.NoError(t, err)
defer cleanupNewCSV()

Expand Down
Loading

0 comments on commit f2a2583

Please sign in to comment.