Skip to content

Commit

Permalink
create update-status function from operator
Browse files Browse the repository at this point in the history
  • Loading branch information
hossainemruz committed Jul 1, 2019
1 parent 955b1ad commit cefa7fb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
stashinformers "stash.appscode.dev/stash/client/informers/externalversions"
"stash.appscode.dev/stash/pkg/eventer"
stash_rbac "stash.appscode.dev/stash/pkg/rbac"
"stash.appscode.dev/stash/pkg/util"
)

const (
Expand Down Expand Up @@ -79,9 +80,17 @@ func (c *Config) New() (*StashController, error) {
recorder: eventer.NewEventRecorder(c.KubeClient, "stash-operator"),
}

// register CRDs
if err := ctrl.ensureCustomResourceDefinitions(); err != nil {
return nil, err
}

// ensure update-status function
err := util.EnsureUpdateStatusFunction(ctrl.stashClient, ctrl.DockerRegistry, ctrl.StashImageTag)
if err != nil {
return nil, err
}

if c.EnableMutatingWebhook {
if err := reg_util.UpdateMutatingWebhookCABundle(c.ClientConfig, mutatingWebhook); err != nil {
return nil, err
Expand Down
40 changes: 40 additions & 0 deletions pkg/util/crd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package util

import (
kerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
api_v1beta1 "stash.appscode.dev/stash/apis/stash/v1beta1"
cs "stash.appscode.dev/stash/client/clientset/versioned"
"stash.appscode.dev/stash/pkg/docker"
)

func EnsureUpdateStatusFunction(stashClient cs.Interface, registry, imageTag string) error {
image := docker.Docker{
Registry: registry,
Image: docker.ImageStash,
Tag: imageTag,
}

updateStatusFunc := &api_v1beta1.Function{
ObjectMeta: metav1.ObjectMeta{
Name: "update-status",
},
Spec: api_v1beta1.FunctionSpec{
Image: image.ToContainerImage(),
Args: []string{
"update-status",
"--namespace=${NAMESPACE:=default}",
"--repository=${REPOSITORY_NAME:=}",
"--restore-session=${RESTORE_SESSION:=}",
"--output-dir=${outputDir:=}",
"--enable-status-subresource=${ENABLE_STATUS_SUBRESOURCE:=false}",
},
},
}

_, err := stashClient.StashV1beta1().Functions().Create(updateStatusFunc)
if err != nil && !kerr.IsAlreadyExists(err) {
return err
}
return nil
}

0 comments on commit cefa7fb

Please sign in to comment.