Skip to content

Commit

Permalink
Merge pull request #214 from Revolyssup/operator
Browse files Browse the repository at this point in the history
Add Undeploy method for controllers
  • Loading branch information
leecalcote authored Sep 14, 2022
2 parents 40de57d + 2d3d212 commit 422737f
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 27 deletions.
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ require (
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/docker/libcompose v0.4.0 // indirect
github.com/emicklei/proto v1.6.15 // indirect
github.com/emirpasic/gods v1.12.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
Expand All @@ -87,7 +86,6 @@ require (
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
Expand Down Expand Up @@ -153,7 +151,6 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/protocolbuffers/txtpbfmt v0.0.0-20201118171849-f6a6b3f636fc // indirect
github.com/rubenv/sql-migrate v0.0.0-20210614095031-55d5740dbbcc // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
Expand All @@ -172,7 +169,6 @@ require (
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/net v0.0.0-20220412020605-290c469a71a5 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
Expand All @@ -181,7 +177,6 @@ require (
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.46.0 // indirect
Expand Down
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubernetes/kompose v1.26.1 h1:jUpXFobChy2U2uqEuk//l7Ur/HzXi0FTAQKRtHCBLbI=
github.com/kubernetes/kompose v1.26.1/go.mod h1:IJd7R1JvhxPSLPAM3MNPGGuHGprVft//t6OTSt1vY5I=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
Expand Down Expand Up @@ -1039,7 +1038,6 @@ github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+v
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2/go.mod h1:iIss55rKnNBTvrwdmkUpLnDpZoAHvWaiq5+iMmen4AE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1-0.20171018195549-f15c970de5b7/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -1371,7 +1369,6 @@ golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hM
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.0 h1:UG21uOlmZabA4fW5i7ZX6bjw1xELEGg/ZLgZq9auk/Q=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1702,7 +1699,6 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f h1:GGU+dLjvlC3qDwqYgL6UgRmHXhOOgns0bZu2Ty5mm6U=
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.2.0/go.mod h1:WXp+iVDkoLQqPudfQ9GBlwB2eZ5DKOnjQZCYdOS8GPY=
google.golang.org/api v0.0.0-20160322025152-9bf6e6e569ff/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
Expand Down Expand Up @@ -1899,7 +1895,6 @@ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0 h1:0vLT13EuvQ0hNvakwLuFZ/jYrLp5F3kcWHXdRggjCE8=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
Expand Down
12 changes: 8 additions & 4 deletions models/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package controllers
type MesheryControllerStatus int

const (
Deployed MesheryControllerStatus = iota
Deploying
NotDeployed
Deployed MesheryControllerStatus = iota //The controller is deployed(default behavior)
Deploying //The controller is being deployed
NotDeployed //The controller is not deployed yet
Undeployed //The controller has been intentionally undeployed. This state is useful to avoid automatic redeployment.
// we don't know since we have not checked yet
Unknown
)
Expand All @@ -18,6 +19,8 @@ func (mcs MesheryControllerStatus) String() string {
return "Deploying"
case NotDeployed:
return "Not Deployed"
case Undeployed:
return "Undeployed"
case Unknown:
return "Unknown"
}
Expand All @@ -27,7 +30,8 @@ func (mcs MesheryControllerStatus) String() string {
type IMesheryController interface {
GetName() string
GetStatus() MesheryControllerStatus
Deploy() error
Deploy(force bool) error //If force is set to false && controller is in "Undeployed", then Deployment will be skipped. Set force=true for explicit install.
Undeploy() error
GetPublicEndpoint() (string, error)
GetVersion() (string, error)
}
2 changes: 1 addition & 1 deletion models/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func applyOperatorHelmChart(chartRepo string, client mesherykube.Client, meshery
}
err := client.ApplyHelmChart(mesherykube.ApplyHelmChartConfig{
Namespace: "meshery",
ReleaseName: "meshery",
ReleaseName: "meshery-operator",
ChartLocation: mesherykube.HelmChartLocation{
Repository: chartRepo,
Chart: chart,
Expand Down
10 changes: 8 additions & 2 deletions models/controllers/meshery_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ func (mb *mesheryBroker) GetStatus() MesheryControllerStatus {
return mb.status
} else {
if kubeerror.IsNotFound(err) {
mb.status = NotDeployed
if mb.status != Undeployed {
mb.status = NotDeployed
}
return mb.status
}
// when operatorClient is not able to get meshesry-broker, we try again with kubernetes client as a fallback
Expand Down Expand Up @@ -77,10 +79,14 @@ func (mb *mesheryBroker) GetStatus() MesheryControllerStatus {
}
}

func (mb *mesheryBroker) Deploy() error {
func (mb *mesheryBroker) Deploy(force bool) error {
// deploying the operator will deploy broker. Right now, we don't need to implement this functionality. But we may implement in the future
return nil
}
func (mb *mesheryBroker) Undeploy() error {
// currently we do not allow the manual undeployment of broker
return nil
}

func (mb *mesheryBroker) GetPublicEndpoint() (string, error) {
operatorClient, err := opClient.New(&mb.kclient.RestConfig)
Expand Down
39 changes: 32 additions & 7 deletions models/controllers/meshery_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"context"
"fmt"
"sync"

mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
kubeerror "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -16,6 +17,7 @@ type mesheryOperator struct {
status MesheryControllerStatus
client *mesherykube.Client
deploymentConf OperatorDeploymentConfig
mx sync.Mutex
}

type OperatorDeploymentConfig struct {
Expand All @@ -38,41 +40,58 @@ func (mo *mesheryOperator) GetName() string {
}

func (mo *mesheryOperator) GetStatus() MesheryControllerStatus {
if mo.status == Undeployed {
return Undeployed
}
// check if the deployment exists
deployment, err := mo.client.DynamicKubeClient.Resource(schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}).Namespace("meshery").Get(context.TODO(), "meshery-operator", metav1.GetOptions{})
if err != nil {
if kubeerror.IsNotFound(err) {
mo.status = NotDeployed
mo.setStatus(NotDeployed)
return mo.status
}
return Unknown
}
mo.status = Deploying

sv, err := polymorphichelpers.StatusViewerFor(deployment.GroupVersionKind().GroupKind())
if err != nil {
mo.status = Unknown
mo.setStatus(Unknown)
return mo.status
}
_, done, err := sv.Status(deployment, 0)
if err != nil {
mo.status = Unknown
mo.setStatus(Unknown)
return mo.status
}
if done {
mo.status = Deployed
mo.setStatus(Deployed)
} else {
mo.setStatus(Deploying)
}
return mo.status
}

func (mo *mesheryOperator) Deploy() error {
if mo.status == Deploying {
func (mo *mesheryOperator) Deploy(force bool) error {
status := mo.GetStatus()
if status == Undeployed && !force {
return nil
}
if status == Deploying {
return ErrDeployController(fmt.Errorf("Already a Meshery Operator is being deployed."))
}
err := applyOperatorHelmChart(mo.deploymentConf.HelmChartRepo, *mo.client, mo.deploymentConf.MesheryReleaseVersion, false, mo.deploymentConf.GetHelmOverrides(false))
if err != nil {
return ErrDeployController(err)
}
mo.setStatus(Deployed)
return nil
}
func (mo *mesheryOperator) Undeploy() error {
err := applyOperatorHelmChart(mo.deploymentConf.HelmChartRepo, *mo.client, mo.deploymentConf.MesheryReleaseVersion, true, mo.deploymentConf.GetHelmOverrides(false))
if err != nil {
return ErrDeployController(err)
}
mo.setStatus(Undeployed)
return nil
}

Expand All @@ -83,3 +102,9 @@ func (mo *mesheryOperator) GetPublicEndpoint() (string, error) {
func (mo *mesheryOperator) GetVersion() (string, error) {
return "", nil
}

func (mo *mesheryOperator) setStatus(st MesheryControllerStatus) {
mo.mx.Lock()
defer mo.mx.Unlock()
mo.status = st
}
10 changes: 8 additions & 2 deletions models/controllers/meshsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ func (ms *meshsync) GetStatus() MesheryControllerStatus {
return ms.status
} else {
if kubeerror.IsNotFound(err) {
ms.status = NotDeployed
if ms.status != Undeployed {
ms.status = NotDeployed
}
return ms.status
}
// when we are not able to get meshSync resource from OperatorClient, we try to get it using kubernetes client
Expand Down Expand Up @@ -74,10 +76,14 @@ func (ms *meshsync) GetStatus() MesheryControllerStatus {
}
}

func (ms *meshsync) Deploy() error {
func (ms *meshsync) Deploy(force bool) error {
// deploying the operator will deploy meshsync. Right now, we don't need to implement this functionality. But we may implement in the future
return nil
}
func (ms *meshsync) Undeploy() error {
// currently we do not allow the manual undeployment of meshsync
return nil
}

func (ms *meshsync) GetPublicEndpoint() (string, error) {
return "", nil
Expand Down
2 changes: 1 addition & 1 deletion utils/artifacthub/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func TestGetChartUrl(t *testing.T) {
}{
// these might change in the future, so the tests have to be changed as well when the urls change
// because the urls will change with every new version update to the package
{AhPackage{Name: "consul", Repository: "bitnami", Organization: ""}, "https://charts.bitnami.com/bitnami/consul-10.8.1.tgz"},
{AhPackage{Name: "consul", Repository: "bitnami", Organization: ""}, "https://charts.bitnami.com/bitnami/consul-10.8.3.tgz"},
{AhPackage{Name: "crossplane-types", Repository: "crossplane", Organization: ""}, "https://charts.crossplane.io/master/crossplane-types-0.13.0-rc.98.g1eb0776.tgz"},
}
for _, tt := range tests {
Expand Down

0 comments on commit 422737f

Please sign in to comment.