Skip to content

Commit abeba6f

Browse files
authored
Merge pull request #26 from keptn-sandbox/bugfixes_operators
changed shipyard handling
2 parents ebacc55 + 37d6d23 commit abeba6f

File tree

6 files changed

+69
-17
lines changed

6 files changed

+69
-17
lines changed

README.md

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,64 @@ The operators in this repository make keptn configurable via Custom Resources an
1212
* In order to be able to create and delete stages, the keptn operator depends on a patched version of the configuration-service and the shipyard controller
1313

1414
## Installation
15+
The operators and the promotion service, which is used to compose the files in the upstream repository are installed via helm. Following, the steps needed for deploying the operators are described.
16+
17+
### Prepare Keys for encryption of secrets
18+
* Download Secrets helper from [Releases](https://github.com/keptn-sandbox/keptn-gitops-operator/releases)
19+
* Create a keypair: ` ./keptn-gitops-secrets-(version) generate-keys -f <prefix>`
20+
* Keep this secrets in a safe place, the public key will be needed for encrypting secrets, the private key to decrypt them on the server-side
21+
22+
### Prepare environment variables
23+
Following, a few parameters have to be set upfront:
24+
* `API_HOSTNAME` describes the hostname of the keptn/cloud automation instance (e.g. my-hostname.keptn.sh)
25+
* `API_TOKEN` describes the Token of the keptn/cloud automation instance
26+
* `RSA_PRIVATE_KEY` represents the private key you created before
27+
* `GITOPS_VERSION` specifies the Version you want to install (see [Releases](https://github.com/keptn-sandbox/keptn-gitops-operator/releases))
28+
1529
```shell
16-
helm install <TBD>
30+
export API_HOSTNAME="<hostname>"
31+
export API_TOKEN="<api-token>"
32+
export RSA_PRIVATE_KEY="<private-key>"
33+
export GITOPS_VERSION="0.1.0-pre.5"
34+
```
35+
36+
### Install Custom Resource Definitions / Create Namespace
37+
```
38+
kubectl create namespace keptn
39+
kubectl apply -f https://github.com/keptn-sandbox/keptn-gitops-operator/releases/download/${GITOPS_VERSION}/keptn-operator_crd.yaml
40+
kubectl apply -f https://github.com/keptn-sandbox/keptn-gitops-operator/releases/download/${GITOPS_VERSION}/gitops-operator_crd.yaml
41+
```
42+
43+
### Install Helm Chart
44+
```
45+
helm upgrade --install --atomic -n keptn keptn-gitops \
46+
https://github.com/keptn-sandbox/keptn-gitops-operator/releases/download/${GITOPS_VERSION}/keptn-gitops-${GITOPS_VERSION}.tgz \
47+
--set global.rsaSecret.privateBase64="${RSA_PUBLIC_KEY}" \
48+
--set promotion-service.remoteControlPlane.enabled=true \
49+
--set promotion-service.remoteControlPlane.api.protocol="https" \
50+
--set promotion-service.remoteControlPlane.api.hostname="${API_HOSTNAME}" --set promotion-service.remoteControlPlane.api.token="${API_TOKEN}"
1751
```
1852

1953
## Keptn Operator
2054
The operator introduces a set of custom resources to make keptn configurable via Kubernetes CRs.
2155

2256
### Custom Resources
23-
| Kind | Purpose | Sample |
24-
|:-------------:|:---------------------------------------------:|:--------------------------------------------------------------------:|
25-
| KeptnProject | Configure a Keptn Project | [./samples/project.yaml](./samples/project.yaml) |
26-
| KeptnService | Configure a Keptn Service | [./samples/service.yaml](./samples/service.yaml) |
27-
| KeptnSequence | Define a Keptn Sequence to be used in a Stage | [./samples/sequence.yaml](./samples/sequence.yaml) |
28-
| KeptnStage | Define a Keptn Stage | [./samples/stage.yaml](./samples/stage.yaml) |
29-
| KeptnSequenceExecution | Triggers a Keptn Sequence Execution | [./samples/sequenceexecution.yaml](./samples/sequenceexecution.yaml) |
57+
| Kind | Purpose | Sample |
58+
|:----------------------:|:---------------------------------------------:|:--------------------------------------------------------------------:|
59+
| KeptnInstance | Configure a Keptn Instance | [./samples/instance.yaml](./samples/instance.yaml) |
60+
| KeptnProject | Configure a Keptn Project | [./samples/project.yaml](./samples/project.yaml) |
61+
| KeptnService | Configure a Keptn Service | [./samples/service.yaml](./samples/service.yaml) |
62+
| KeptnSequence | Define a Keptn Sequence to be used in a Stage | [./samples/sequence.yaml](./samples/sequence.yaml) |
63+
| KeptnStage | Define a Keptn Stage | [./samples/stage.yaml](./samples/stage.yaml) |
64+
| KeptnServiceDeployment | Specifies the deployed version of a service | [./samples/servicedeployment.yaml](./samples/servicedeployment.yaml) |
3065

3166
### Usage:
3267
* Create an empty upstream repository
68+
* Create a KeptnInstance Custom Resource according to the [sample](./samples/instance.yaml). You can specify the secret to your secret either in clear text or RSA as an RSA encrypted string (prefix this with rsa:)
3369
* Create a KeptnProject Custom Resource according to the [sample](./samples/project.yaml). You can specify the secret to your secret either in clear text or RSA as an RSA encrypted string (prefix this with rsa:)
3470
* Create your keptn services according to the [sample](./samples/service.yaml). Ensure that you added the correct project.
3571
* Create stages, and sequences. Ensure that you created the sequences you are referring to in the stage custom resources
36-
* Define a sequence execution to trigger a keptn event
72+
* Define a service deployment to deploy the service
3773

3874
## GitOps Operator
3975
The operator looks for configuration in a git repository, applies Keptn Custom Resources (see above) and pushes artifacts to the Keptn Upstream Repository.

gitops-operator/config/crd/bases/keptn.sh_keptnprojects.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ spec:
3737
properties:
3838
defaultBranch:
3939
type: string
40+
initialShipyard:
41+
type: string
4042
password:
4143
type: string
4244
repository:
@@ -48,6 +50,9 @@ spec:
4850
type: object
4951
status:
5052
description: KeptnProjectStatus defines the observed state of KeptnProject
53+
properties:
54+
projectExists:
55+
type: boolean
5156
type: object
5257
type: object
5358
served: true

keptn-operator/api/v1/keptnproject_types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ type KeptnProjectSpec struct {
2929
// Important: Run "make" to regenerate code after modifying this file
3030

3131
// Foo is an example field of KeptnProject. Edit keptnproject_types.go to remove/update
32-
Repository string `json:"repository,omitempty"`
33-
Username string `json:"username,omitempty"`
34-
Password string `json:"password,omitempty"`
35-
DefaultBranch string `json:"defaultBranch,omitempty"`
32+
Repository string `json:"repository,omitempty"`
33+
Username string `json:"username,omitempty"`
34+
Password string `json:"password,omitempty"`
35+
InitialShipyard string `json:"initialShipyard,omitempty"`
36+
DefaultBranch string `json:"defaultBranch,omitempty"`
3637
}
3738

3839
// KeptnProjectStatus defines the observed state of KeptnProject

keptn-operator/config/crd/bases/keptn.sh_keptnprojects.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ spec:
3838
properties:
3939
defaultBranch:
4040
type: string
41+
initialShipyard:
42+
type: string
4143
password:
4244
type: string
4345
repository:

keptn-operator/controllers/keptnprojectcontroller/keptnproject_controller.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ func (r *KeptnProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request
144144
}
145145
return ctrl.Result{RequeueAfter: reconcileErrorInterval}, nil
146146
} else if !keptnproject.Status.ProjectExists {
147+
147148
keptnproject.Status.ProjectExists = true
148-
err := r.Client.Status().Update(ctx, keptnproject)
149+
150+
err = r.Client.Status().Update(ctx, keptnproject)
149151
if err != nil {
150152
r.ReqLogger.Error(err, "Could not update status of project "+keptnproject.Name)
151153
return r.finishReconcile(err, false)
@@ -220,6 +222,7 @@ func (r *KeptnProjectReconciler) deleteKeptnProject(keptnproject *apiv1.KeptnPro
220222
}
221223

222224
func (r *KeptnProjectReconciler) createProject(project *apiv1.KeptnProject) error {
225+
var shipyard string
223226
httpclient := nethttp.Client{
224227
Timeout: 30 * time.Second,
225228
}
@@ -230,11 +233,17 @@ func (r *KeptnProjectReconciler) createProject(project *apiv1.KeptnProject) erro
230233
return err
231234
}
232235

236+
if project.Spec.InitialShipyard == "" {
237+
shipyard = "YXBpVmVyc2lvbjogInNwZWMua2VwdG4uc2gvMC4yLjAiCmtpbmQ6ICJTaGlweWFyZCIKbWV0YWRhdGE6CiAgbmFtZTogInBvZHRhdG8taGVhZCIKc3BlYzoKICBzdGFnZXM6CiAgICAtIG5hbWU6ICJkZXYiCiAgICAgIHNlcXVlbmNlczoKICAgICAgICAtIG5hbWU6ICJkdW1teSIKICAgICAgICAgIHRhc2tzOgogICAgICAgICAgICAtIG5hbWU6ICJkdW1teSIKICAgIC0gbmFtZTogImhhcmRlbmluZyIKICAgICAgc2VxdWVuY2VzOgogICAgICAgIC0gbmFtZTogImR1bW15IgogICAgICAgICAgdGFza3M6CiAgICAgICAgICAgIC0gbmFtZTogImR1bW15IgogICAgLSBuYW1lOiAicHJvZHVjdGlvbiIKICAgICAgc2VxdWVuY2VzOgogICAgICAgIC0gbmFtZTogImR1bW15IgogICAgICAgICAgdGFza3M6CiAgICAgICAgICAgIC0gbmFtZTogImR1bW15IgoK"
238+
} else {
239+
shipyard = project.Spec.InitialShipyard
240+
}
241+
233242
data, _ := json.Marshal(map[string]string{
234243
"gitRemoteURL": project.Spec.Repository,
235244
"gitToken": secret,
236245
"gitUser": project.Spec.Username,
237-
"shipyard": "YXBpVmVyc2lvbjogInNwZWMua2VwdG4uc2gvMC4yLjAiCmtpbmQ6ICJTaGlweWFyZCIKbWV0YWRhdGE6CiAgbmFtZTogInBvZHRhdG8taGVhZCIKc3BlYzoKICBzdGFnZXM6CiAgICAtIG5hbWU6ICJkZXYiCiAgICAgIHNlcXVlbmNlczoKICAgICAgICAtIG5hbWU6ICJkdW1teSIKICAgICAgICAgIHRhc2tzOgogICAgICAgICAgICAtIG5hbWU6ICJkdW1teSIKICAgIC0gbmFtZTogImhhcmRlbmluZyIKICAgICAgc2VxdWVuY2VzOgogICAgICAgIC0gbmFtZTogImR1bW15IgogICAgICAgICAgdGFza3M6CiAgICAgICAgICAgIC0gbmFtZTogImR1bW15IgogICAgLSBuYW1lOiAicHJvZHVjdGlvbiIKICAgICAgc2VxdWVuY2VzOgogICAgICAgIC0gbmFtZTogImR1bW15IgogICAgICAgICAgdGFza3M6CiAgICAgICAgICAgIC0gbmFtZTogImR1bW15IgoK",
246+
"shipyard": shipyard,
238247
"name": project.Name,
239248
})
240249

keptn-operator/pkg/utils/keptn.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ func GetKeptnInstance(ctx context.Context, client client.Client, namespace strin
6262

6363
//CheckKeptnProjectExists queries the keptn api if a project exists
6464
func CheckKeptnProjectExists(ctx context.Context, req ctrl.Request, clt client.Client, project string) (bool, error) {
65-
6665
instance, token, err := GetKeptnInstance(ctx, clt, req.Namespace)
6766
if err != nil {
68-
67+
return false, err
6968
}
7069
projectsHandler := apiutils.NewAuthenticatedProjectHandler(instance.Spec.APIUrl, token, instance.Status.AuthHeader, nil, instance.Status.Scheme)
7170

0 commit comments

Comments
 (0)