Skip to content

Implement a Devfile Registry operator #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/dockerimage-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright (c) 2020 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
name: Next Dockerimage

on:
push:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- name: Checkout registry-operator source code
uses: actions/checkout@v2
- name: Docker Build & Push
uses: docker/[email protected]
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
repository: devfile/registry-operator
dockerfile: Dockerfile
tags: next
tag_with_sha: true
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN go mod download
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ ENVTEST_ASSETS_DIR = $(shell pwd)/testbin
test: generate fmt vet manifests
mkdir -p $(ENVTEST_ASSETS_DIR)
test -f $(ENVTEST_ASSETS_DIR)/setup-envtest.sh || curl -sSLo $(ENVTEST_ASSETS_DIR)/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.6.3/hack/setup-envtest.sh
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
source $(ENVTEST_ASSETS_DIR)/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./pkg/... -coverprofile cover.out

### test-integration: runs integration tests on the cluster set in context.
test-integration: generate fmt vet manifests
CGO_ENABLED=0 go test -v -c -o bin/devfileregistry-operator-integration ./tests/integration/cmd/devfileregistry_test.go
./bin/devfileregistry-operator-integration

# Build manager binary
manager: generate fmt vet
Expand All @@ -45,9 +50,10 @@ run: generate fmt vet manifests
install: manifests kustomize
$(KUSTOMIZE) build config/crd | kubectl apply -f -

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

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests kustomize
Expand Down
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
# registry-operator
Operator for devfile registry
# Devfile Registry Operator

Devfile Registry operator repository that contains the operator for the DevfileRegistry Custom Resource.

## Issue Tracking

Issue tracking repo: https://github.com/devfile/api with label area/registry

## Running the controller in a cluster

The controller can be deployed to a cluster provided you are logged in with cluster-admin credentials:

```bash
export IMG=quay.io/devfile/registry-operator:next
make install && make deploy
```

## Development

The repository contains a Makefile; building and deploying can be configured via the environment variables

|variable|purpose|default value|
|---|---|---|
| `IMG` | Image used for controller | `quay.io/devfile/registry-operator:next` |

Some of the rules supported by the makefile:

|rule|purpose|
|---|---|
| docker-build | build registry operator docker image |
| docker-push | push registry operator docker image |
| deploy | deploy operator to cluster |
| install | create the devfile registry CRDs on the cluster |
| uninstall | remove the devfile registry operator and CRDs from the cluster |
| manifests | Generate manifests e.g. CRD, RBAC etc. |
| generate | Generate the API type definitions. Must be run after modifying the DevfileRegistry type. |
| test_integration | Run the integration tests for the operator. |

To see all rules supported by the makefile, run `make help`

## Testing

To run integration tests for the operator, run `make test_integration`.

By default, the tests will use the default image for the operator, `quay.io/devfile/registry-operator:next`. To use your own image, run:

```
export IMG=<your-operator-image>
make test_integration
```

### Run operator locally
It's possible to run an instance of the operator locally while communicating with a cluster.

```bash
export NAMESPACE=devfileregistry-operator
make run ENABLE_WEBHOOKS=false
```
47 changes: 45 additions & 2 deletions api/v1alpha1/devfileregistry_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,63 @@ type DevfileRegistrySpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Foo is an example field of DevfileRegistry. Edit DevfileRegistry_types.go to remove/update
Foo string `json:"foo,omitempty"`
// Sets the container image containing devfile stacks to be deployed on the Devfile Registry
DevfileIndexImage string `json:"devfileIndexImage,omitempty"`

// Overrides the container image used for the OCI registry.
// Recommended to leave blank and default to the image specified by the operator.
// +optional
OciRegistryImage string `json:"ociRegistryImage,omitempty"`
Storage DevfileRegistrySpecStorage `json:"storage,omitempty"`
TLS DevfileRegistrySpecTLS `json:"tls,omitempty"`
K8s DevfileRegistrySpecK8sOnly `json:"k8s,omitempty"`
}

// DevfileRegistrySpecStorage defines the desired state of the storage for the DevfileRegistry
type DevfileRegistrySpecStorage struct {
// Instructs the operator to deploy the DevfileRegistry with persistent storage
// Enabled by default. Disabling is only recommended for development or test.
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Configures the size of the devfile registry's persistent volume, if enabled.
// Defaults to 1Gi.
// +optional
RegistryVolumeSize string `json:"ociRegistryImage,omitempty"`
}

// DevfileRegistrySpecTLS defines the desired state for TLS in the DevfileRegistry
type DevfileRegistrySpecTLS struct {
// Instructs the operator to deploy the DevfileRegistry with TLS enabled.
// Enabled by default. Disabling is only recommended for development or test.
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Name of an optional, pre-existing TLS secret to use for TLS termination on ingress/route resources.
// +optional
SecretName string `json:"ociRegistryImage,omitempty"`
}

// DevfileRegistrySpecK8sOnly defines the desired state of the kubernetes-only fields of the DevfileRegistry
type DevfileRegistrySpecK8sOnly struct {
// Ingress domain for a Kubernetes cluster. This MUST be explicitly specified on Kubernetes. There are no defaults
IngressDomain string `json:"ingressDomain,omitempty"`
}

// DevfileRegistryStatus defines the observed state of DevfileRegistry
type DevfileRegistryStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
URL string `json:"url"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// DevfileRegistry is the Schema for the devfileregistries API
// +kubebuilder:resource:path=devfileregistries,shortName=devreg;dr
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="URL",type="string",JSONPath=".status.url",description="The URL for the Devfile Registry"
type DevfileRegistry struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down
60 changes: 59 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 61 additions & 3 deletions config/crd/bases/registry.devfile.io_devfileregistries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ metadata:
creationTimestamp: null
name: devfileregistries.registry.devfile.io
spec:
additionalPrinterColumns:
- JSONPath: .status.url
description: The URL for the Devfile Registry
name: URL
type: string
group: registry.devfile.io
names:
kind: DevfileRegistry
listKind: DevfileRegistryList
plural: devfileregistries
shortNames:
- devreg
- dr
singular: devfileregistry
scope: Namespaced
subresources:
Expand All @@ -36,13 +44,63 @@ spec:
spec:
description: DevfileRegistrySpec defines the desired state of DevfileRegistry
properties:
foo:
description: Foo is an example field of DevfileRegistry. Edit DevfileRegistry_types.go
to remove/update
devfileIndexImage:
description: Sets the container image containing devfile stacks to be
deployed on the Devfile Registry
type: string
k8s:
description: DevfileRegistrySpecK8sOnly defines the desired state of
the kubernetes-only fields of the DevfileRegistry
properties:
ingressDomain:
description: Ingress domain for a Kubernetes cluster. This MUST
be explicitly specified on Kubernetes. There are no defaults
type: string
type: object
ociRegistryImage:
description: Overrides the container image used for the OCI registry.
Recommended to leave blank and default to the image specified by the
operator.
type: string
storage:
description: DevfileRegistrySpecStorage defines the desired state of
the storage for the DevfileRegistry
properties:
enabled:
description: Instructs the operator to deploy the DevfileRegistry
with persistent storage Enabled by default. Disabling is only
recommended for development or test.
type: boolean
ociRegistryImage:
description: Configures the size of the devfile registry's persistent
volume, if enabled. Defaults to 1Gi.
type: string
type: object
tls:
description: DevfileRegistrySpecTLS defines the desired state for TLS
in the DevfileRegistry
properties:
enabled:
description: Instructs the operator to deploy the DevfileRegistry
with TLS enabled. Enabled by default. Disabling is only recommended
for development or test.
type: boolean
ociRegistryImage:
description: Name of an optional, pre-existing TLS secret to use
for TLS termination on ingress/route resources.
type: string
type: object
type: object
status:
description: DevfileRegistryStatus defines the observed state of DevfileRegistry
properties:
url:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file'
type: string
required:
- url
type: object
type: object
version: v1alpha1
Expand Down
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/devfile/registry-operator
newTag: next
4 changes: 4 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,26 @@ metadata:
namespace: system
labels:
control-plane: controller-manager
app.kubernetes.io/name: devfileregistry-operator
spec:
selector:
matchLabels:
control-plane: controller-manager
app.kubernetes.io/name: devfileregistry-operator
replicas: 1
template:
metadata:
labels:
control-plane: controller-manager
app.kubernetes.io/name: devfileregistry-operator
spec:
containers:
- command:
- /manager
args:
- --enable-leader-election
image: controller:latest
imagePullPolicy: Always
name: manager
resources:
limits:
Expand Down
Loading