Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Bump operator sdk v1.13.0 #376

Merged
merged 2 commits into from
Feb 2, 2022
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ orbs:
executors:
operator-build:
docker:
- image: orangeopensource/casskop-build:v0.19.4
- image: orangeopensource/casskop-build:v1.13.0
# Define jobs list
jobs:
# Build job, which build operator docker image (with operator-sdk build)
Expand Down Expand Up @@ -323,6 +323,11 @@ jobs:
operatorDir: casskop/multi-casskop
operatorName: MultiCassKop

## Parameters anchors
.params_multicasskop_build: &params_multicasskop_build
operatorDir: casskop
operatorName: MultiCassKop

# Workflow definition
workflows:
version: 2
Expand Down Expand Up @@ -412,7 +417,7 @@ workflows:

- operator/build:
name: build-multicasskop
<<: *params_multicasskop
<<: *params_multicasskop_build
requires:
- generate-multicasskop
<<: *everytime_filter
Expand Down
19 changes: 9 additions & 10 deletions build/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@ ENV GO111MODULE=on
RUN useradd -u 1000 casskop
RUN mkdir -p /tmp && chown casskop /tmp

ADD tools tools
RUN cd tools/health && go build -o ../../health main.go
ADD . /casskop

WORKDIR /casskop

ADD . casskop
WORKDIR casskop
RUN go mod download

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o casskop main.go

FROM gcr.io/distroless/base

WORKDIR /
COPY --from=build /etc/passwd /etc/passwd
COPY --from=build /go/health /
COPY --from=build /tmp /tmp
COPY --from=build /casskop/casskop /usr/local/bin/casskop
USER casskop

LABEL org.opencontainers.image.documentation="https://github.com/Orange-OpenSource/casskop/blob/master/README.md"
LABEL org.opencontainers.image.authors="Sébastien Allamand <sebastien.allamand@orange.com>"
Expand All @@ -29,16 +32,12 @@ LABEL org.opencontainers.image.url="https://github.com/Orange-OpenSource/casskop
LABEL org.opencontainers.image.title="Operateur Cassandra"

LABEL org.label-schema.usage="https://github.com/Orange-OpenSource/casskop/blob/master/README.md"
LABEL org.label-schema.docker.cmd="/usr/local/bin/casskop"
LABEL org.label-schema.docker.cmd.devel="N/A"
LABEL org.label-schema.docker.cmd.test="N/A"
LABEL org.label-schema.docker.cmd.help="N/A"
LABEL org.label-schema.docker.cmd.debug="N/A"
LABEL org.label-schema.docker.params="LOG_LEVEL=define loglevel,RESYNC_PERIOD=period in second to execute resynchronisation,WATCH_NAMESPACE=namespace to watch for cassandraclusters,OPERATOR_NAME=name of the operator instance pod"

# install operator binary
COPY build/_output/bin/casskop /usr/local/bin/

USER casskop

CMD ["/usr/local/bin/casskop"]
ENTRYPOINT ["/usr/local/bin/casskop"]
19 changes: 9 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,20 @@ SPEC_PROPS = $(FIRST_VERSION).schema.openAPIV3Schema.properties.spec.properties
.PHONY: update-crds
update-crds:
echo Update CRD - Remove protocol and set config type to object CRD
@sed -i '/\- protocol/d' deploy/crds/db.orange.com_cassandraclusters.yaml
@yq -i e '$(SPEC_PROPS).config.type = "object"' deploy/crds/db.orange.com_cassandraclusters.yaml
@yq -i e '$(SPEC_PROPS).topology.properties.dc.items.properties.config.type = "object"' deploy/crds/db.orange.com_cassandraclusters.yaml
@yq -i e '$(SPEC_PROPS).topology.properties.dc.items.properties.rack.items.properties.config.type = "object"' deploy/crds/db.orange.com_cassandraclusters.yaml
# We checkout v1alpha1 CRD and add it to v2 CRD as it must be known to do an upgrade
for crd in deploy/crds/*.yaml; do \
@sed -i '/\- protocol/d' config/crd/bases/db.orange.com_cassandraclusters.yaml
@yq -i e '$(SPEC_PROPS).config.type = "object"' config/crd/bases/db.orange.com_cassandraclusters.yaml
@yq -i e '$(SPEC_PROPS).topology.properties.dc.items.properties.config.type = "object"' config/crd/bases/db.orange.com_cassandraclusters.yaml
@yq -i e '$(SPEC_PROPS).topology.properties.dc.items.properties.rack.items.properties.config.type = "object"' config/crd/bases/db.orange.com_cassandraclusters.yaml
for crd in config/crd/bases/*.yaml; do \
crdname=$$(basename $$crd); \
end=$$(expr $$(grep -n ^status $$crd|cut -f1 -d:) - 1); \
git show v1.1.5-release:$$(echo $$crd|sed 's/.yaml/_crd.yaml/') $$crd > /tmp/$$crdname; \
git show v1.1.5-release:$$(echo deploy/crds/$$crdname |sed 's/.yaml/_crd.yaml/') $$crd > /tmp/$$crdname; \
sed -e '1,/versions/d' -e "1,$${end}s/^..//" $$crd >> /tmp/$$crdname; \
cp /tmp/$$crdname $$crd; \
yq -i e '$(FIRST_VERSION).storage = false' $$crd; \
done
cp -v deploy/crds/* helm/*/crds/
cp -v deploy/crds/* */helm/*/crds/
cp -v config/crd/bases/* helm/*/crds/
cp -v config/crd/bases/* */helm/*/crds/

include shared.mk
include kube.mk
Expand Down Expand Up @@ -192,7 +191,7 @@ debug-kubesquash:
# Run the development environment (in local go env) in the background using local ~/.kube/config
run:
export POD_NAME=casskop; \
operator-sdk up local
go run ./main.go

push:
docker push $(REPOSITORY):$(VERSION)
Expand Down
16 changes: 16 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
domain: db.orange.com
layout: go.kubebuilder.io/v2
repo: github.com/Orange-OpenSource/casskop
resources:
- group: db.orange.com
kind: CassandraBackup
version: v2
- group: db.orange.com
kind: CassandraCluster
version: v2
- group: db.orange.com
kind: CassandraRestore
version: v2
version: 3-alpha
plugins:
go.operator-sdk.io/v2-alpha: {}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@ func (backupSpec CassandraBackupSpec) ValidateScheduleFormat() error {

type CassandraBackupSpec struct {
// Name of the CassandraCluster to backup
CassandraCluster string `json:"cassandraCluster"`
CassandraCluster string `json:"cassandraCluster"`
// Cassandra DC name to back up, used to find the cassandra nodes in the CassandraCluster
Datacenter string `json:"datacenter,omitempty"`
Datacenter string `json:"datacenter,omitempty"`
// URI for the backup target location e.g. s3 bucket, filepath
StorageLocation string `json:"storageLocation"`
StorageLocation string `json:"storageLocation"`
// Specify a schedule to assigned to the backup. The schedule doesn't enforce anything so if you schedule multiple
// backups around the same time they would conflict. See https://godoc.org/github.com/robfig/cron for more information regarding the supported formats
Schedule string `json:"schedule,omitempty"`
Schedule string `json:"schedule,omitempty"`
// name of snapshot to make so this snapshot will be uploaded to storage location. If not specified, the name of
// snapshot will be automatically generated and it will have name 'autosnap-milliseconds-since-epoch'
SnapshotTag string `json:"snapshotTag"`
SnapshotTag string `json:"snapshotTag"`
// Specify a duration the backup should try to last. See https://golang.org/pkg/time/#ParseDuration for an
// exhaustive list of the supported units. You can use values like .25h, 15m, 900s all meaning 15 minutes
Duration string `json:"duration,omitempty"`
Duration string `json:"duration,omitempty"`
// Specify the bandwidth to not exceed when uploading files to the cloud. Format supported is \d+[KMG] case
// insensitive. You can use values like 10M (meaning 10MB), 1024, 1024K, 2G, etc...
Bandwidth string `json:"bandwidth,omitempty"`
Bandwidth string `json:"bandwidth,omitempty"`
// Maximum number of threads used to download files from the cloud. Defaults to 10
ConcurrentConnections int32 `json:"concurrentConnections,omitempty"`
ConcurrentConnections int32 `json:"concurrentConnections,omitempty"`
// Database entities to backup, it might be either only keyspaces or only tables prefixed by their respective
// keyspace, e.g. 'k1,k2' if one wants to backup whole keyspaces or 'ks1.t1,ks2.t2' if one wants to restore specific
// tables. These formats are mutually exclusive so 'k1,k2.t2' is invalid. An empty field will backup all keyspaces
Entities string `json:"entities,omitempty"`
Entities string `json:"entities,omitempty"`
// Name of Secret to use when accessing cloud storage providers
Secret string `json:"secret,omitempty"`
Secret string `json:"secret,omitempty"`
}

type BackupConditionType string
Expand All @@ -68,16 +68,16 @@ func (b BackupConditionType) HasFailed() bool {
return b == BackupFailed
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

// Defines a backup operation and its details
// CassandraBackup is the Schema for the cassandrabackups API
// +k8s:openapi-gen=true
type CassandraBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec CassandraBackupSpec `json:"spec"`
Status BackRestStatus `json:"status,omitempty"`
Spec CassandraBackupSpec `json:"spec"`
Status BackRestStatus `json:"status,omitempty"`
}

func (cb *CassandraBackup) PreventBackupDeletion(value bool) {
Expand Down Expand Up @@ -112,8 +112,9 @@ func (cb *CassandraBackup) ComputeLastAppliedAnnotation() (string, error) {
return string(lastApplied), err
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

// CassandraBackupList contains a list of CassandraBackup
type CassandraBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand All @@ -123,17 +124,16 @@ type CassandraBackupList struct {
func init() {
SchemeBuilder.Register(&CassandraBackup{}, &CassandraBackupList{})
}

func ComputeBackupStatus(backupOperationResponse *icarus.BackupOperationResponse,
coordinatorMember string) BackRestStatus{
coordinatorMember string) BackRestStatus {
logrus.Infof("backupOperationResponse object: %+v", backupOperationResponse)

return BackRestStatus{
Progress: ProgressPercentage(backupOperationResponse.Progress),
ID: backupOperationResponse.Id,
TimeCreated: backupOperationResponse.CreationTime,
TimeStarted: backupOperationResponse.StartTime,
TimeCompleted: backupOperationResponse.CompletionTime,
Progress: ProgressPercentage(backupOperationResponse.Progress),
ID: backupOperationResponse.Id,
TimeCreated: backupOperationResponse.CreationTime,
TimeStarted: backupOperationResponse.StartTime,
TimeCompleted: backupOperationResponse.CompletionTime,
CoordinatorMember: coordinatorMember,
Condition: &BackRestCondition{
LastTransitionTime: metav1.Now().Format(util.TimeStampLayout),
Expand All @@ -157,4 +157,4 @@ func (backupSpec *CassandraBackup) IsGcpBackup() bool {

func (backupSpec *CassandraBackup) IsFileBackup() bool {
return strings.HasPrefix(backupSpec.Spec.StorageLocation, "file://")
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
// Copyright 2019 Orange
//
// 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 v2

import (
"encoding/json"
"fmt"
"regexp"
"strings"

"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"regexp"
"strings"
)

const (
Expand Down Expand Up @@ -55,7 +40,7 @@ const (
//DefaultDelayWaitForDecommission is the time to wait for the decommission to happen on the Pod
//The operator will start again if it is not the case
DefaultDelayWaitForDecommission = 120
)
)

// ClusterStateInfo describe a cluster state
type ClusterStateInfo struct {
Expand Down Expand Up @@ -345,39 +330,39 @@ func (cc *CassandraCluster) InitSeedList() []string {
return seedList
}
for dc := 0; dc < dcsize; dc++ {
dcName = cc.GetDCName(dc)
var nbSeedInDC int = 0
racksize := cc.GetRackSize(dc)
dcName = cc.GetDCName(dc)
var nbSeedInDC int = 0
racksize := cc.GetRackSize(dc)

if racksize < 1 {
rackName = DefaultCassandraRack
nbRack++
for indice = 0; indice < cc.Spec.NodesPerRacks && indice < 3; indice++ {
if racksize < 1 {
rackName = DefaultCassandraRack
nbRack++
for indice = 0; indice < cc.Spec.NodesPerRacks && indice < 3; indice++ {
cc.addNewSeed(&seedList, dcName, rackName, indice)
}
continue
}
for rack := 0; rack < racksize; rack++ {
rackName = cc.GetRackName(dc, rack)
dcRackName := cc.GetDCRackName(dcName, rackName)
nbRack++
nodesPerRacks := cc.GetNodesPerRacks(dcRackName)

switch racksize {
case 1, 2:
for indice = 0; indice < nodesPerRacks && indice < int32(4-racksize) &&
nbSeedInDC < 3; indice++ {
cc.addNewSeed(&seedList, dcName, rackName, indice)
nbSeedInDC++
}
continue
}
for rack := 0; rack < racksize; rack++ {
rackName = cc.GetRackName(dc, rack)
dcRackName := cc.GetDCRackName(dcName, rackName)
nbRack++
nodesPerRacks := cc.GetNodesPerRacks(dcRackName)

switch racksize {
case 1, 2:
for indice = 0; indice < nodesPerRacks && indice < int32(4 - racksize) &&
nbSeedInDC < 3; indice++ {
cc.addNewSeed(&seedList, dcName, rackName, indice)
nbSeedInDC++
}
default:
if nbSeedInDC < 3 {
cc.addNewSeed(&seedList, dcName, rackName, 0)
nbSeedInDC++
}
default:
if nbSeedInDC < 3 {
cc.addNewSeed(&seedList, dcName, rackName, 0)
nbSeedInDC++
}
}
}
}
return seedList
}

Expand Down Expand Up @@ -904,7 +889,6 @@ type Rack struct {

//The Partition to control the Statefulset Upgrade
RollingPartition int32 `json:"rollingPartition,omitempty"`

}

// PodPolicy defines the policy for pods owned by CassKop operator.
Expand Down Expand Up @@ -1011,7 +995,7 @@ type CassandraNodeStatus struct {
NodeIp string `json:"nodeIp,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

// CassandraCluster is the Schema for the cassandraclusters API
// +k8s:openapi-gen=true
Expand All @@ -1026,13 +1010,13 @@ type CassandraCluster struct {
Status CassandraClusterStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true

// CassandraClusterList contains a list of CassandraCluster
type CassandraClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CassandraCluster `json:"items"`
Items []CassandraCluster `json:"items"`
}

func init() {
Expand Down
Loading