Skip to content

Commit

Permalink
Merge branch 'main' into nitishm/bug/216/tilt-create-ns
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishm committed May 18, 2021
2 parents 3e6545b + dfe5e00 commit ae0125d
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 65 deletions.
9 changes: 3 additions & 6 deletions chart/orkestra/Chart.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ dependencies:
- name: argo
repository: https://argoproj.github.io/argo-helm
version: 0.16.8
- name: helm-operator
repository: https://charts.fluxcd.io
version: 1.2.0
- name: helm-controller
repository: https://nitishm.github.io/charts
version: 0.1.0
digest: sha256:dbaa6bb947e68c751aeb07f569cc1b18761922a9dc209b8189980ed36735c00d
generated: "2021-04-22T10:12:19.315706-07:00"
version: 0.1.1
digest: sha256:7f2f2e1f5efdec11d929472f4779a4ea014355570cf2294d6958b65765463cbb
generated: "2021-05-14T12:59:31.637787-07:00"
2 changes: 1 addition & 1 deletion chart/orkestra/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
repository: "https://argoproj.github.io/argo-helm"
- name: helm-controller
condition: helm-controller.enabled
version: "0.1.0"
version: "0.1.1"
repository: "https://nitishm.github.io/charts"

keywords:
Expand Down
Binary file removed chart/orkestra/charts/helm-controller-0.1.0.tgz
Binary file not shown.
Binary file added chart/orkestra/charts/helm-controller-0.1.1.tgz
Binary file not shown.
3 changes: 2 additions & 1 deletion chart/orkestra/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ debug:
# Dependency overlay values
chartmuseum:
name: chartmuseum
interval: 5m
interval: 10s
env:
open:
DISABLE_API: false
Expand Down Expand Up @@ -86,6 +86,7 @@ argo:
createServiceAccount: false

helm-controller:
concurrent: 20
enabled: true
serviceAccount:
create: false
Expand Down
4 changes: 0 additions & 4 deletions config/samples/bookinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ spec:
# name: <secret-name>
# namespace: <secret-namespace>
release:
upgrade:
force: true
targetNamespace: ambassador
values:
service:
Expand All @@ -45,8 +43,6 @@ spec:
- name: details
dependencies: []
release:
upgrade:
force: true
targetNamespace: bookinfo
values:
productpage:
Expand Down
98 changes: 83 additions & 15 deletions controllers/appgroup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,104 @@ package controllers

import (
"context"
"github.com/Azure/Orkestra/api/v1alpha1"
"github.com/Azure/Orkestra/pkg/meta"
v1alpha12 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
fluxhelmv2beta1 "github.com/fluxcd/helm-controller/api/v2beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"time"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("ApplicationGroup Controller", func() {
BeforeEach(func() {
// Add any setup steps that needs to be executed before each test
})

AfterEach(func() {
// Add any teardown steps that needs to be executed after each test
})
Context("ApplicationGroup", func() {
var (
namespace *corev1.Namespace
ctx context.Context
)

const (
DefaultNamesapce = "orkestra"
)

BeforeEach(func() {
// TODO: Namespace will be added once we have the namespace based support for ApplicationGroup
namespace = &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "appgroup-test" + randStringRunes(5),
},
}
ctx = context.Background()
_ = k8sClient.Create(ctx, namespace)
//Expect(err).ToNot(HaveOccurred())

Context("Submit Bookinfo ApplicationGroup", func() {
It("Should create successfully", func() {
// applicationGroupKey := types.NamespacedName{
// Name: "bookinfo",
// }
})

AfterEach(func() {
err := k8sClient.Delete(ctx, namespace)
Expect(err).ToNot(HaveOccurred())
})

It("Should create Bookinfo spec successfully", func() {
ctx := context.Background()
applicationGroup := bookinfo()
applicationGroup.Namespace = DefaultNamesapce
key := client.ObjectKeyFromObject(applicationGroup)

By("Applying the bookinfo object to the cluster")
Expect(k8sClient.Create(context.Background(), applicationGroup)).Should(Succeed())
time.Sleep(time.Second * 5)
err := k8sClient.Create(ctx, applicationGroup)
Expect(err).ToNot(HaveOccurred())

// Defer the cleanup so that we delete the appGroup after creation
defer func() {
Expect(k8sClient.Delete(context.Background(), applicationGroup)).Should(Succeed())
time.Sleep(time.Second * 5)
By("Deleting the bookinfo object from the cluster")
patch := client.MergeFrom(applicationGroup.DeepCopy())
controllerutil.RemoveFinalizer(applicationGroup, "application-group-finalizer")
_ = k8sClient.Patch(ctx, applicationGroup, patch)
_ = k8sClient.Delete(ctx, applicationGroup)
}()

helmReleaseList := &fluxhelmv2beta1.HelmReleaseList{}
err = k8sClient.List(ctx, helmReleaseList)
Expect(err).ToNot(HaveOccurred())
oldHelmReleaseCount := len(helmReleaseList.Items)

By("Making sure that the workflow goes into a running state")
Eventually(func() bool {
workflow := &v1alpha12.Workflow{}
workflowKey := types.NamespacedName{Name: applicationGroup.Name, Namespace: applicationGroup.Namespace}
_ = k8sClient.Get(ctx, workflowKey, workflow)
return workflow.Status.Phase == v1alpha12.NodeRunning
}, time.Minute, time.Second).Should(BeTrue())

By("Waiting for the bookinfo object to reach a succeeded reason")
Eventually(func() bool {
applicationGroup = &v1alpha1.ApplicationGroup{}
if err := k8sClient.Get(ctx, key, applicationGroup); err != nil {
return false
}
return applicationGroup.GetReadyCondition() == meta.SucceededReason
}, time.Minute*4, time.Second).Should(BeTrue())

By("checking that the all the HelmReleases have come up and are in a ready state")
err = k8sClient.List(ctx, helmReleaseList)
Expect(err).ToNot(HaveOccurred())
Expect(len(helmReleaseList.Items)).To(Equal(oldHelmReleaseCount + 6))
allReady := true
for _, release := range helmReleaseList.Items {
if condition := meta.GetResourceCondition(&release, meta.ReadyCondition); condition.Reason == meta.SucceededReason {
allReady = false
}
}
Expect(allReady).To(BeTrue())

})
})
})
12 changes: 11 additions & 1 deletion controllers/testutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"io/ioutil"
"log"
"math/rand"

orkestrav1alpha1 "github.com/Azure/Orkestra/api/v1alpha1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -18,7 +19,6 @@ func bookinfo() *orkestrav1alpha1.ApplicationGroup {
Name: "bookinfo",
},
}

yamlFile, err := ioutil.ReadFile(bookinfoExampleFilePath)
if err != nil {
log.Fatalf("yamlFile.Get err #%v", err)
Expand All @@ -32,3 +32,13 @@ func bookinfo() *orkestrav1alpha1.ApplicationGroup {

return g
}

var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz1234567890")

func randStringRunes(n int) string {
b := make([]rune, n)
for i := range b {
b[i] = letterRunes[rand.Intn(len(letterRunes))]
}
return string(b)
}
5 changes: 1 addition & 4 deletions examples/simple/bookinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ spec:
# name: <secret-name>
# namespace: <secret-namespace>
release:
upgrade:
force: true
timeout: 10m
targetNamespace: ambassador
values:
service:
Expand All @@ -44,8 +43,6 @@ spec:
- name: details
dependencies: []
release:
upgrade:
force: true
targetNamespace: bookinfo
values:
productpage:
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ go 1.15
require (
github.com/argoproj/argo v2.5.2+incompatible
github.com/chartmuseum/helm-push v0.9.0
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fluxcd/helm-controller/api v0.9.0
github.com/fluxcd/pkg/apis/meta v0.9.0
github.com/fluxcd/source-controller/api v0.12.2
github.com/go-logr/logr v0.4.0
github.com/go-openapi/spec v0.19.5 // indirect
github.com/gofrs/flock v0.8.0
Expand All @@ -15,8 +16,8 @@ require (
github.com/jinzhu/copier v0.3.0
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/onsi/ginkgo v1.16.1 // indirect
github.com/onsi/gomega v1.11.0 // indirect
github.com/onsi/ginkgo v1.16.1
github.com/onsi/gomega v1.11.0
go.opencensus.io v0.22.5 // indirect
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 // indirect
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,13 @@ github.com/fluxcd/helm-controller/api v0.9.0 h1:L60KmCblTQo3UimgCzVQGe330tC+b15C
github.com/fluxcd/helm-controller/api v0.9.0/go.mod h1:HIWSF3n1QU3hdqjQMFizFUZVr1uV+abmlGAEpB7vB9A=
github.com/fluxcd/pkg/apis/kustomize v0.0.1 h1:TkA80R0GopRY27VJqzKyS6ifiKIAfwBd7OHXtV3t2CI=
github.com/fluxcd/pkg/apis/kustomize v0.0.1/go.mod h1:JAFPfnRmcrAoG1gNiA8kmEXsnOBuDyZ/F5X4DAQcVV0=
github.com/fluxcd/pkg/apis/meta v0.8.0 h1:wqWpUsxhKHB1ZztcvOz+vnyhdKW9cWmjFp8Vci/XOdk=
github.com/fluxcd/pkg/apis/meta v0.8.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
github.com/fluxcd/pkg/apis/meta v0.9.0 h1:rxW69p+VmJCKXXkaRYnovRBFlKjd+MJQfm2RrB0B4j8=
github.com/fluxcd/pkg/apis/meta v0.9.0/go.mod h1:yHuY8kyGHYz22I0jQzqMMGCcHViuzC/WPdo9Gisk8Po=
github.com/fluxcd/pkg/runtime v0.10.1 h1:NV0pe6lFzodKBIz0dT3xkoR0wJnTCicXwM/v/d5T0+Y=
github.com/fluxcd/pkg/runtime v0.10.1/go.mod h1:JD0eZIn5xkTeHHQUWXSqJPIh/ecO0d0qrUKbSVHnpnw=
github.com/fluxcd/source-controller/api v0.12.2 h1:8n9+poUv/6bAEgteTxKV591aKzqRIv391VS8uD1imzo=
github.com/fluxcd/source-controller/api v0.12.2/go.mod h1:+EPyhxC7Y+hUnq7EwAkkLtfbwCxJxF5yfmiyzDk43KY=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
Expand Down Expand Up @@ -342,7 +345,6 @@ github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.1 h1:OQl5ys5MBea7OGCdvPbBJWRgnhC/fGona6QKfvFeau8=
Expand Down Expand Up @@ -621,7 +623,6 @@ github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OS
github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand All @@ -638,16 +639,13 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.14.2 h1:8mVmC9kjFFmA8H4pKMUhcblgifdkOIXPvbhN1T36q1M=
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.16.1 h1:foqVmeWDD6yYpK+Yz3fHyNIxFYNxswxqNFjSKe+vI54=
github.com/onsi/ginkgo v1.16.1/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.2 h1:aY/nuoWlKJud2J6U0E3NWsjlg+0GtwXxgEqthRdzlcs=
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.11.0 h1:+CqWgvj0OZycCaqclBD1pxKHAU+tOkHmQIWvDHq2aug=
github.com/onsi/gomega v1.11.0/go.mod h1:azGKhqFUon9Vuj0YmTfLSmx0FUwqXYSTl5re8lQLTUg=
Expand Down Expand Up @@ -964,7 +962,6 @@ golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81R
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb h1:eBmm0M9fYhWpKZLjQUUKka/LtIxf46G4fxeEz5KJr9U=
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
Expand Down Expand Up @@ -1117,7 +1114,6 @@ golang.org/x/tools v0.0.0-20200616133436-c1934b75d054/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d h1:W07d4xkoAUSNOkOzdzXCdFGxT7o2rW4q8M34tB2i//k=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e h1:4nW4NLDYnU28ojHaHO8OVxFHk/aQ33U01a9cjED+pzE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
52 changes: 38 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package main

import (
"context"
"flag"
"os"
"time"

"github.com/Azure/Orkestra/pkg"
"github.com/Azure/Orkestra/pkg/registry"
Expand Down Expand Up @@ -75,6 +77,15 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseDevMode(false)))
}

// Start the probe at the very beginning
probe, err := pkg.ProbeHandler(stagingRepoURL, "health")
if err != nil {
setupLog.Error(err, "unable to start readiness/liveness probes", "controller", "ApplicationGroup")
os.Exit(1)
}

probe.Start("8086")

ctrl.Log.V(debugLevel)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Expand Down Expand Up @@ -108,12 +119,33 @@ func main() {
}

// Register the staging helm repository/registry
err = rc.AddRepo(&registry.Config{
Name: "staging",
URL: stagingRepoURL,
})
if err != nil {
setupLog.Error(err, "failed to add staging helm repo")
// We perform retry on this so that we don't go into a crash loop backoff
retryChan := make(chan bool)
retryCtx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
go func() {
for {
err = rc.AddRepo(&registry.Config{
Name: "staging",
URL: stagingRepoURL,
})
if err != nil {
setupLog.Info("failed to add staging helm repo, retrying...")
time.Sleep(time.Second * 5)
} else {
retryChan <- true
break
}
}
}()
select {
case <-retryChan:
cancel()
close(retryChan)
setupLog.Info("successfully set-up the local chartmuseum helm repository")
case <-retryCtx.Done():
cancel()
close(retryChan)
setupLog.Error(err, "pod timed out while trying to setup the helm chart museum...")
os.Exit(1)
}

Expand All @@ -134,14 +166,6 @@ func main() {
}
// +kubebuilder:scaffold:builder

probe, err := pkg.ProbeHandler(stagingRepoURL, "health")
if err != nil {
setupLog.Error(err, "unable to start readiness/liveness probes", "controller", "ApplicationGroup")
os.Exit(1)
}

probe.Start("8086")

setupLog.Info("starting manager")
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
Expand Down
Loading

0 comments on commit ae0125d

Please sign in to comment.