Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40 from integr8ly/INTLY-2000
Browse files Browse the repository at this point in the history
Intly 2000
  • Loading branch information
pb82 authored May 8, 2019
2 parents 3a8b870 + d333480 commit b64c904
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions pkg/deploys/fuse/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/yaml"
"net/http"
Expand All @@ -26,6 +27,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
fusePullSecretName = "syndesis-pull-secret"
fusePullSecretKey = ".dockerconfigjson"
)

type FuseDeployer struct {
k8sClient kubernetes.Interface
osClient *openshift.ClientFactory
Expand Down Expand Up @@ -61,6 +67,14 @@ func (fd *FuseDeployer) Deploy(req *brokerapi.ProvisionRequest, async bool) (*br

namespace := ns.ObjectMeta.Name

err = fd.createImagePullSecret(namespace)
if err != nil {
glog.Errorln(err)
return &brokerapi.ProvisionResponse{
Code: http.StatusInternalServerError,
}, err
}

err = fd.createOperatorResources(namespace, fd.client)
if err != nil {
glog.Errorln(err)
Expand Down Expand Up @@ -94,6 +108,38 @@ func (fd *FuseDeployer) Deploy(req *brokerapi.ProvisionRequest, async bool) (*br
}, nil
}

// Creates the syndesis pull secret required to pull images from registry.redhat.io
func (fd *FuseDeployer) createImagePullSecret(userNamespace string) error {
operatorNamespace := os.Getenv("POD_NAMESPACE")
if operatorNamespace == "" {
return errors.New("POD_NAMESPACE must be set")
}

pullSecret, err := fd.k8sClient.CoreV1().Secrets(operatorNamespace).Get(fusePullSecretName, metav1.GetOptions{})
if err != nil {
return err
}

if _, ok := pullSecret.Data[fusePullSecretKey]; !ok {
return errors.New(fmt.Sprintf("%s does not contain a key named %s", fusePullSecretName, fusePullSecretKey))
}

_, err = fd.k8sClient.CoreV1().Secrets(userNamespace).Create(&corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: userNamespace,
Name: fusePullSecretName,
},
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Secret",
},
Type: "kubernetes.io/dockerconfigjson",
Data: pullSecret.Data,
})

return err
}

func (fd *FuseDeployer) createOperatorResources(namespace string, client client.Client) error {
resourcesUrl, exists := os.LookupEnv("FUSE_OPERATOR_RESOURCES_URL")
if !exists {
Expand Down

0 comments on commit b64c904

Please sign in to comment.