Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
83 changes: 15 additions & 68 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,77 +1,24 @@
# Temporary Build Files
build/_output
build/_test
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
# -*- mode: gitignore; -*-
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Org-mode
.org-id-locations
*_archive
# flymake-mode
*_flymake.*
# eshell files
/eshell/history
/eshell/lastdir
# elpa packages
/elpa/
# reftex files
*.rel
# AUCTeX auto folder
/auto/
# cask packages
.cask/
dist/
# Flycheck
flycheck_*.el
# server auth directory
/server/
# projectiles files
.projectile
projectile-bookmarks.eld
# directory configuration
.dir-locals.el
# saveplace
places
# url cache
url/cache/
# cedet
ede-projects.el
# smex
smex-items
# company-statistics
company-statistics-cache.el
# anaconda-mode
anaconda-mode/
### Go ###

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, build with 'go test -c'
bin

# Test binary, build with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
### Vim ###
# swap
.sw[a-p]
.*.sw[a-p]
# session
Session.vim
# temporary
.netrwhist
# auto-generated tag files
tags
### VisualStudioCode ###
.vscode/*
.history
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode

# Kubernetes Generated files - skip generated files, except for vendored files

!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
*.swp
*.swo
*~
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM docker.io/openshift/origin-release:golang-1.13 AS builder
WORKDIR /go/src/github.com/openshift/cincinnati-operator/
COPY . .
RUN go build -mod=vendor -o /tmp/build/cincinnati-operator github.com/openshift/cincinnati-operator/cmd/manager
RUN go build -mod=vendor -o /tmp/build/update-service-operator github.com/openshift/cincinnati-operator

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

COPY --from=builder /tmp/build/cincinnati-operator /usr/bin/cincinnati-operator
ENTRYPOINT ["/usr/bin/cincinnati-operator"]
COPY --from=builder /tmp/build/update-service-operator /usr/bin/update-service-operator
ENTRYPOINT ["/usr/bin/update-service-operator"]
158 changes: 145 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,153 @@
.PHONY: \
clean \
deploy \
func-test \
unit-test
# Current Operator version
VERSION ?= 0.0.1
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)

clean:
@echo "Cleaning previous outputs"
rm functests/functests.test
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
OPERAND_IMAGE ?= cincinnati:latest
GRAPH_DATA_IMAGE ?= graph-data:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"

deploy:
@echo "Deploying Cincinnati operator"
hack/deploy.sh
ifneq (, $(shell which kubectl))
KUBECTL=$(shell which kubectl)
else ifneq (, $(shell which oc))
KUBECTL=$(shell which oc)
else
KUBECTL=kubectl
endif

func-test: deploy
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

all: manager

# Run tests
test: generate fmt vet manifests
go test ./... -coverprofile cover.out

# Build manager binary
manager: generate fmt vet
go build -o bin/manager main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go

# Install CRDs into a cluster
install: manifests kustomize
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -

# Uninstall CRDs from a cluster
uninstall: manifests kustomize
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete -f -

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize patch-deployment
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

# Run go fmt against code
fmt:
go fmt ./...

# Run go vet against code
vet:
go vet ./...

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# Patch OPERAND_IMAGE, because that is not currently possible via kustomize.
# https://github.com/kubernetes-sigs/kustomize/issues/2301
patch-deployment:
sed -i 's|cincinnati:latest|$(OPERAND_IMAGE)|' config/manager/manager.yaml

# Build the docker image
docker-build: #test
docker build -t ${IMG} .

# Push the docker image
docker-push:
docker push ${IMG}

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

kustomize:
ifneq (, $(shell which kustomize))
KUSTOMIZE=$(shell which kustomize)
else ifneq (, $(shell which oc))
KUSTOMIZE=$(shell which oc) kustomize
else
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
endif

# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests patch-deployment
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

# Build the bundle image.
.PHONY: bundle-build
bundle-build:
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

# Transitional openshift/release compatibility
deploy-without-regenerating-manifests: kustomize patch-deployment
# No v3 kustomize in the CI container
#cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
sed -i 's|controller:latest|$(OPERATOR_IMAGE)|' config/manager/manager.yaml
oc kustomize config/default | $(KUBECTL) apply -f -

func-test: deploy-without-regenerating-manifests
@echo "Running functional test suite"
sed -i 's|graph-data:latest|$(GRAPH_DATA_IMAGE)|' config/samples/cincinnati_v1beta1_cincinnati.yaml
go test -v ./functests/...

unit-test:
@echo "Executing unit tests"
go test -v ./pkg/...
go test -v ./controllers/...
11 changes: 11 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
domain: openshift.io
layout: go.kubebuilder.io/v2
projectName: openshift-update-service
repo: github.com/openshift/cincinnati-operator
resources:
- group: updateservice
kind: UpdateService
version: v1
version: 3-alpha
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
# cincinnati-operator
# OpenShift Update Service Operator

This operator is developed using the [operator SDK][operator-sdk], version 0.18.
This operator is developed using the [operator SDK][operator-sdk], version 1.0.
Installation docs are [here][operator-sdk-installation].

## Run locally

To run locally, you must set the operand image as shown below.

```
```sh
export OPERAND_IMAGE="quay.io/app-sre/cincinnati:2873c6b"
operator-sdk run --local
export IMG="example.com/you/update-service-operator:latest" # somewhere you can push
make docker-build
make docker-push
make deploy
```

## Using an init container to load graph data

The Cincinnati graph data is loaded from an init container. Before deploying
the cincinnati-operator, you will need to [build and push an init container containing the graph data](docs/graph-data-init-container.md).
The graph data is loaded from an init container.
Before deploying the Update Service operator, you will need to [build and push an init container containing the graph data](docs/graph-data-init-container.md).

## Deploy operator

```
make deploy
```

By default, operator will be deployed using the default operator image `quay.io/cincinnati/cincinnati-operator:latest`. If you want to override the default operator image with your image, set
By default, operator will be deployed using the default operator image `controller:latest`. If you want to override the default operator image with your image, set

```
export OPERATOR_IMAGE="your-registry/your-repo/your-cincinnati-opertor-image:tag"
export IMG="your-registry/your-repo/your-update-service-opertor-image:tag"
```

## Run functional tests
Expand All @@ -49,4 +52,4 @@ make unit-test
```

[operator-sdk]: https://sdk.operatorframework.io/docs/
[operator-sdk-installation]: https://v0-18-x.sdk.operatorframework.io/docs/install-operator-sdk/
[operator-sdk-installation]: https://v1-0-x.sdk.operatorframework.io/docs/installation/install-operator-sdk/
36 changes: 36 additions & 0 deletions api/v1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*


Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1 contains API Schema definitions for the updateservice v1 API group
// +kubebuilder:object:generate=true
// +groupName=updateservice.openshift.io
package v1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "updateservice.openshift.io", Version: "v1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
Loading