Skip to content

Commit

Permalink
Add Operator UUID to config status
Browse files Browse the repository at this point in the history
This allows us to generate and push new operator image which when run
will apply all the yaml files again.
  • Loading branch information
sthaha committed Dec 3, 2019
1 parent ceb9f71 commit 43dbf38
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions build/Dockerfile
Expand Up @@ -12,6 +12,9 @@ RUN /usr/local/bin/user_setup

COPY deploy/resources /deploy/resources

# UBI8 image missing uuidgen
RUN cat /proc/sys/kernel/random/uuid > /deploy/uuid

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}
2 changes: 2 additions & 0 deletions build/bin/entrypoint
Expand Up @@ -9,4 +9,6 @@ if ! whoami &>/dev/null; then
fi
fi

export OPERATOR_UUID=$(cat /deploy/uuid)

exec ${OPERATOR} $@
1 change: 1 addition & 0 deletions cmd/manager/main.go
Expand Up @@ -43,6 +43,7 @@ func printVersion() {
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
log.Info(fmt.Sprintf("Version of operator-sdk: %v", sdkVersion.Version))
log.Info(fmt.Sprintf("Operator UUID: %v", operator.OperatorUUID))
}

func main() {
Expand Down
5 changes: 5 additions & 0 deletions deploy/crds/operator_v1alpha1_config_crd.yaml
Expand Up @@ -49,11 +49,16 @@ spec:
- version
type: object
type: array
operatorUUID:
type: string
description: UUID of the operator that installed the pipeline
type: object
additionalPrinterColumns:
- JSONPath: ".status.conditions[0].code"
name: status
type: string
description: status of pipeline installation

version: v1alpha1
versions:
- name: v1alpha1
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/operator/v1alpha1/config_types.go
Expand Up @@ -15,6 +15,10 @@ type ConfigSpec struct {
// +k8s:openapi-gen=true
type ConfigStatus struct {

// OperatorUUID is the uuid (auto-generated) of the operator that
// installed the pipeline
OperatorUUID string `json:"operatorUUID,omitempty"`

// installation status sorted in reverse chronological order
Conditions []ConfigCondition `json:"conditions,omitempty"`
}
Expand Down
13 changes: 10 additions & 3 deletions pkg/controller/config/config_controller.go
Expand Up @@ -357,6 +357,7 @@ func (r *ReconcileConfig) updateStatus(cfg *op.Config, c op.ConfigCondition) err
// to prevent us from using stale version of the object

tmp := cfg.DeepCopy()
tmp.Status.OperatorUUID = flag.OperatorUUID
tmp.Status.Conditions = append([]op.ConfigCondition{c}, tmp.Status.Conditions...)

if err := r.client.Status().Update(context.TODO(), tmp); err != nil {
Expand Down Expand Up @@ -397,15 +398,21 @@ func createCR(c client.Client) error {
return err
}

func isUpToDate(r *op.Config) bool {
c := r.Status.Conditions
func isUpToDate(cfg *op.Config) bool {
c := cfg.Status.Conditions
if len(c) == 0 {
return false
}

latest := c[0]
return latest.Version == flag.TektonVersion &&
latest.Code == op.InstalledStatus
latest.Code == op.InstalledStatus &&
matchesUUID(cfg.Status.OperatorUUID)
}

func matchesUUID(target string) bool {
uuid := flag.OperatorUUID
return uuid == "" || uuid == target
}

func requestLogger(req reconcile.Request, context string) logr.Logger {
Expand Down
5 changes: 4 additions & 1 deletion pkg/flag/flag.go
@@ -1,6 +1,7 @@
package flag

import (
"os"
"path/filepath"

"github.com/spf13/pflag"
Expand All @@ -23,7 +24,7 @@ const (

// Name of the trigger deployment
TriggerControllerName = "tekton-triggers-controller"
TriggerWebhookName = "tekton-triggers-webhook"
TriggerWebhookName = "tekton-triggers-webhook"
)

var (
Expand All @@ -37,9 +38,11 @@ var (
TargetNamespace string
NoAutoInstall bool
Recursive bool
OperatorUUID string
)

func init() {
OperatorUUID = os.Getenv("OPERATOR_UUID")
flagSet = pflag.NewFlagSet("operator", pflag.ExitOnError)
flagSet.StringVar(
&PipelineSA, "rbac-sa", DefaultSA,
Expand Down

0 comments on commit 43dbf38

Please sign in to comment.