Commit 153a7335 authored by Edmund Ochieng's avatar Edmund Ochieng

Merge branch 'ochienged/operator-v1_migration'

parents ab3397f6 b4d63072
Pipeline #184504463 passed with stages
in 10 minutes and 27 seconds
# Temporary Build Files
build/_output
build/_test
# Generated manager Golang binary
bin/manager
config/manifests/*.yaml
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
### Emacs ###
# -*- mode: gitignore; -*-
......@@ -76,5 +76,4 @@ tags
.history
# Local build tools
Makefile
local
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
image: golang:1.14
stages:
- prepare
- test
- build
variables:
GOPATH: ${CI_PROJECT_DIR}/.go
before_script:
- mkdir -p .go
- go get -u github.com/onsi/ginkgo/ginkgo
- go get -u golang.org/x/lint/golint
.cache:
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .go/
lint_code:
stage: prepare
script:
- .go/bin/golint -set_exit_status $(go list ./... | grep -v /vendor/)
extends: .cache
unit_tests:
stage: test
script:
- mkdir coverage
- .go/bin/go test ./... -coverprofile cover.out
extends: .cache
build_all:
stage: build
script:
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo ./...
extends: .cache
# Build the manager binary
FROM golang:1.13 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest
LABEL name=gitlab-operator \
......@@ -5,22 +26,16 @@ LABEL name=gitlab-operator \
description='Operator to deploy GitLab and Runner instances' \
summary='GitLab is a DevOps lifecycle tool that provides Git repositories'
ENV OPERATOR=/usr/local/bin/gitlab-operator \
USER_UID=1001 \
USER_NAME=gitlab-operator
ENV USER_UID=1001
# ADD GITLAB LICENSE
COPY LICENSE /licenses/GITLAB
# Copy config templates
COPY build/assets /
# install operator binary
COPY build/_output/bin/gitlab-operator ${OPERATOR}
COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup
ENTRYPOINT ["/usr/local/bin/entrypoint"]
COPY hack/assets /
WORKDIR /
COPY --from=builder /workspace/manager .
USER ${USER_UID}
ENTRYPOINT ["/manager"]
Copyright (c) 2011-present GitLab B.V.
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
Portions of this software are licensed as follows:
http://www.apache.org/licenses/LICENSE-2.0
* All content residing under the "doc/" directory of this repository is licensed under "Creative Commons: CC BY-SA 4.0 license".
* All content that resides under the "ee/" directory of this repository, if that directory exists, is licensed under the license defined in "ee/LICENSE".
* All client-side JavaScript (when served directly or after being compiled, arranged, augmented, or combined), is licensed under the "MIT Expat" license.
* All third party components incorporated into the GitLab Software are licensed under the original license provided by the owner of the applicable component.
* Content outside of the above mentioned directories or restrictions above is available under the "MIT Expat" license as defined below.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
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.
# 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)
# Image URL to use all building/pushing image targets
IMG ?= registry.gitlab.com/gitlab-org/gl-openshift/gitlab-operator:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# 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
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="./..."
# Build the docker image
docker-build: test # Pending https://github.com/kubernetes-sigs/kubebuilder/pull/1626
podman build . -t ${IMG}
# Push the docker image
docker-push:
podman 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/controller-gen@v0.3.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif
# Generate bundle manifests and metadata, then validate generated files.
.PHONY: bundle
bundle: manifests
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:
podman build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
# Generate install manifests
deploy-manifests:
rm -f config/manifests/*.yaml
kustomize build --output config/manifests config/default
domain: gitlab.com
layout: go.kubebuilder.io/v2
projectName: gitlab-operator
repo: gitlab.com/gitlab-org/gl-openshift/gitlab-operator
resources:
- group: apps
kind: GitLab
version: v1beta1
- group: apps
kind: Runner
version: v1beta1
- group: apps
kind: GLBackup
version: v1beta1
version: 3-alpha
plugins:
go.sdk.operatorframework.io/v2-alpha: {}
/*
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 v1beta1
import (
acmev1alpha2 "github.com/jetstack/cert-manager/pkg/apis/acme/v1alpha2"
acmev1beta1 "github.com/jetstack/cert-manager/pkg/apis/acme/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// GitlabSpec defines the desired state of Gitlab
type GitlabSpec struct {
Replicas int32 `json:"replicas"`
// GitLabSpec defines the desired state of GitLab
type GitLabSpec struct {
Release string `json:"release,omitempty"`
URL string `json:"url,omitempty"`
TLS string `json:"tls,omitempty"`
......@@ -68,7 +83,8 @@ type SMTPConfiguration struct {
Domain string `json:"domain,omitempty"`
// Username represents the SMTP username for sending email
Username string `json:"username,omitempty"`
// Password represents the password for SMTP user
// Password contains name of secret containing
// the password for SMTP user
Password string `json:"password,omitempty"`
// Authentication represents authentication mechanism
// Options include: login, plain, cram_md5
......@@ -108,12 +124,12 @@ type ACMEOptions struct {
// ExternalAccountBinding is a reference to a CA external account of the ACME
// server.
// +optional
ExternalAccountBinding *acmev1alpha2.ACMEExternalAccountBinding `json:"externalAccountBinding,omitempty"`
ExternalAccountBinding *acmev1beta1.ACMEExternalAccountBinding `json:"externalAccountBinding,omitempty"`
// Solvers is a list of challenge solvers that will be used to solve
// ACME challenges for the matching domains.
// +optional
Solvers []acmev1alpha2.ACMEChallengeSolver `json:"solvers,omitempty"`
Solvers []acmev1beta1.ACMEChallengeSolver `json:"solvers,omitempty"`
}
// VolumeSpec defines volume specifications
......@@ -135,15 +151,6 @@ type ComponentVolumeSpec struct {
Repositories VolumeSpec `json:"repositories,omitempty"`
}
// GitlabStatus defines the observed state of Gitlab
type GitlabStatus struct {
// Phase represents status of the Gitlab resource
Phase string `json:"phase,omitempty"`
Release string `json:"release,omitempty"`
Stage string `json:"stage,omitempty"`
HealthCheck *HealthCheck `json:"health,omitempty"`
}
// HealthCheck represents the status
// of services that make up Gitlab
type HealthCheck struct {
......@@ -152,28 +159,36 @@ type HealthCheck struct {
Workhorse string `json:"workhorse,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// GitLabStatus defines the observed state of GitLab
type GitLabStatus struct {
Phase string `json:"phase,omitempty"`
Release string `json:"release,omitempty"`
Stage string `json:"stage,omitempty"`
HealthCheck *HealthCheck `json:"health,omitempty"`
}
// Gitlab is the Schema for the gitlabs API
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=gl
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=gitlabs,scope=Namespaced
type Gitlab struct {
// GitLab is the Schema for the gitlabs API
type GitLab struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec GitlabSpec `json:"spec,omitempty"`
Status GitlabStatus `json:"status,omitempty"`
Spec GitLabSpec `json:"spec,omitempty"`
Status GitLabStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// GitlabList contains a list of Gitlab
type GitlabList struct {
// GitLabList contains a list of GitLab
type GitLabList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Gitlab `json:"items"`
Items []GitLab `json:"items"`
}
func init() {
SchemeBuilder.Register(&Gitlab{}, &GitlabList{})
SchemeBuilder.Register(&GitLab{}, &GitLabList{})
}
/*
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 v1beta1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// BackupSpec defines the desired state of Backup
type BackupSpec struct {
// GLBackupSpec defines the desired state of GLBackup
type GLBackupSpec struct {
// Instance represents the GitLab instance to backup
Instance string `json:"instance"`
// Schedule defines the time and day to run backup
// It takes cron time format
Schedule string `json:"schedule,omitempty"`
// Exclusions allows user to exclude components to backup
......@@ -43,8 +60,8 @@ const (
BackupScheduled BackupState = "Scheduled"
)
// BackupStatus defines the observed state of Backup
type BackupStatus struct {
// GLBackupStatus defines the observed state of GLBackup
type GLBackupStatus struct {
// +kubebuilder:validation:Enum=Running;Completed;Scheduled;Failed
Phase BackupState `json:"phase,omitempty"`
......@@ -55,28 +72,28 @@ type BackupStatus struct {
CompletedAt string `json:"completedAt,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Backup is the Schema for the backups API
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=gbk
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=backups,scope=Namespaced
type Backup struct {
// GLBackup is the Schema for the glbackups API
type GLBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BackupSpec `json:"spec,omitempty"`
Status BackupStatus `json:"status,omitempty"`
Spec GLBackupSpec `json:"spec,omitempty"`
Status GLBackupStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// BackupList contains a list of Backup
type BackupList struct {
// GLBackupList contains a list of GLBackup
type GLBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Backup `json:"items"`
Items []GLBackup `json:"items"`
}
func init() {
SchemeBuilder.Register(&Backup{}, &BackupList{})
SchemeBuilder.Register(&GLBackup{}, &GLBackupList{})
}
/*
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 v1beta1 contains API Schema definitions for the apps v1beta1 API group
// +kubebuilder:object:generate=true
// +groupName=apps.gitlab.com
package v1beta1
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: "apps.gitlab.com", Version: "v1beta1"}
// 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
)