Skip to content

Commit 1389b9d

Browse files
authored
Merge pull request #183 from raghavendra-talur/rtalur-fix-2255411
Bug 2255411: Backport of upstream PRs 1171, 1173, 1174
2 parents 90e3ce1 + 0e08909 commit 1389b9d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1643
-2062
lines changed

.github/workflows/ci.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env:
2323
IMAGE_NAME: ${{ vars.IMAGE_NAME || 'ramen' }}
2424
OPERATOR_SUGGESTED_NAMESPACE: ${{ vars.OPERATOR_SUGGESTED_NAMESPACE || 'ramen-system' }}
2525
# Constants
26-
GO_VERSION: "1.19"
26+
GO_VERSION: "1.21"
2727
IMAGE_REGISTRY: "quay.io"
2828
IMAGE_TAG: "ci"
2929
DOCKERCMD: "podman"
@@ -39,6 +39,11 @@ jobs:
3939
- name: Checkout source
4040
uses: actions/checkout@v3
4141

42+
- name: Setup go
43+
uses: actions/setup-go@v4
44+
with:
45+
go-version: ${{ env.GO_VERSION }}
46+
4247
- name: Install prereqs
4348
run: |
4449
echo 'APT::Acquire::Retries "5";' | sudo tee /etc/apt/apt.conf.d/80-retries

Dockerfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Build the manager binary
5-
FROM golang:1.19.1 as builder
5+
FROM docker.io/library/golang:1.21 as builder
66

77
WORKDIR /workspace
88
# Copy the Go Modules manifests
99
COPY go.mod go.mod
1010
COPY go.sum go.sum
11+
COPY api/ api/
1112
# cache deps before building and copying source so that we don't need to re-download as much
1213
# and so that source changes don't invalidate our downloaded layer
1314
RUN go mod download
1415

1516
# Copy the go source
1617
COPY main.go main.go
17-
COPY api/ api/
1818
COPY controllers/ controllers/
1919

2020
# Build
21-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
21+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
2222

23-
FROM registry.access.redhat.com/ubi8/ubi
23+
FROM registry.access.redhat.com/ubi8/ubi-minimal
2424
WORKDIR /
2525
COPY --from=builder /workspace/manager .
2626

Makefile

+7-47
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ IMAGE_NAME ?= ramen
3838
IMAGE_TAG ?= latest
3939
PLATFORM ?= k8s
4040
IMAGE_TAG_BASE = $(IMAGE_REGISTRY)/$(IMAGE_REPOSITORY)/$(IMAGE_NAME)
41-
RBAC_PROXY_IMG ?= "gcr.io/kubebuilder/kube-rbac-proxy:v0.13.0"
41+
RBAC_PROXY_IMG ?= "gcr.io/kubebuilder/kube-rbac-proxy:v0.13.1"
4242
OPERATOR_SUGGESTED_NAMESPACE ?= ramen-system
4343
AUTO_CONFIGURE_DR_CLUSTER ?= true
4444
KUBE_OBJECT_PROTECTION_DISABLED ?= false
@@ -126,7 +126,7 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and
126126

127127
.PHONY: golangci-bin
128128
golangci-bin:
129-
hack/install-golangci-lint.sh
129+
@hack/install-golangci-lint.sh
130130

131131
.PHONY: lint
132132
lint: golangci-bin ## Run configured golangci-lint and pre-commit.sh linters against the code.
@@ -255,48 +255,20 @@ undeploy-dr-cluster: kustomize ## Undeploy dr-cluster controller from the K8s cl
255255
##@ Tools
256256

257257
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
258-
controller_gen_version=v0.9.2
259258
controller-gen: ## Download controller-gen locally if necessary.
260-
@test '$(shell $(CONTROLLER_GEN) --version)' = 'Version: $(controller_gen_version)' ||\
261-
$(call go-get-tool,sigs.k8s.io/controller-tools/cmd/controller-gen@$(controller_gen_version))
259+
@hack/install-controller-gen.sh
262260

261+
.PHONY: kustomize
263262
KUSTOMIZE = $(shell pwd)/bin/kustomize
264263
kustomize: ## Download kustomize locally if necessary.
265-
@test -f $(KUSTOMIZE) ||\
266-
$(call go-get-tool,sigs.k8s.io/kustomize/kustomize/[email protected])
267-
268-
# go-get-tool will 'go get' any package $1 and install it to bin/.
269-
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
270-
define go-get-tool
271-
{ \
272-
set -e ;\
273-
TMP_DIR=$$(mktemp -d) ;\
274-
cd $$TMP_DIR ;\
275-
go mod init tmp ;\
276-
echo "Downloading $(1)" ;\
277-
GOBIN=$(PROJECT_DIR)/bin go install $(1) ;\
278-
rm -rf $$TMP_DIR ;\
279-
}
280-
endef
264+
@hack/install-kustomize.sh
281265

282266
##@ Bundle
283267

284268
.PHONY: operator-sdk
285269
OSDK = ./bin/operator-sdk
286270
operator-sdk: ## Download operator-sdk locally if necessary.
287-
ifeq (,$(wildcard $(OSDK)))
288-
ifeq (,$(shell which operator-sdk 2>/dev/null))
289-
@{ \
290-
set -e ;\
291-
mkdir -p $(dir $(OSDK)) ;\
292-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
293-
curl -sSLo $(OSDK) https://github.com/operator-framework/operator-sdk/releases/download/v1.24.0/operator-sdk_$${OS}_$${ARCH} ;\
294-
chmod +x $(OSDK) ;\
295-
}
296-
else
297-
OSDK = $(shell which operator-sdk)
298-
endif
299-
endif
271+
@hack/install-operator-sdk.sh
300272

301273
.PHONY: bundle
302274
bundle: bundle-hub bundle-dr-cluster ## Generate all bundle manifests and metadata, then validate generated files.
@@ -355,19 +327,7 @@ bundle-dr-cluster-push: ## Push the dr-cluster bundle image.
355327
.PHONY: opm
356328
OPM = ./bin/opm
357329
opm: ## Download opm locally if necessary.
358-
ifeq (,$(wildcard $(OPM)))
359-
ifeq (,$(shell which opm 2>/dev/null))
360-
@{ \
361-
set -e ;\
362-
mkdir -p $(dir $(OPM)) ;\
363-
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
364-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.2/$${OS}-$${ARCH}-opm ;\
365-
chmod +x $(OPM) ;\
366-
}
367-
else
368-
OPM = $(shell which opm)
369-
endif
370-
endif
330+
@./hack/install-opm.sh
371331

372332
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
373333
# These images MUST exist in a registry and be pull-able.

api/v1alpha1/drcluster_webhook.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
ctrl "sigs.k8s.io/controller-runtime"
1111
logf "sigs.k8s.io/controller-runtime/pkg/log"
1212
"sigs.k8s.io/controller-runtime/pkg/webhook"
13+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1314
)
1415

1516
// log is for logging in this package.
@@ -27,50 +28,50 @@ func (r *DRCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
2728
var _ webhook.Validator = &DRCluster{}
2829

2930
// ValidateCreate checks
30-
func (r *DRCluster) ValidateCreate() error {
31+
func (r *DRCluster) ValidateCreate() (admission.Warnings, error) {
3132
drclusterlog.Info("validate create", "name", r.Name)
3233

3334
return r.ValidateDRCluster()
3435
}
3536

3637
// ValidateUpdate checks
37-
func (r *DRCluster) ValidateUpdate(old runtime.Object) error {
38+
func (r *DRCluster) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
3839
drclusterlog.Info("validate update", "name", r.Name)
3940

4041
oldDRCluster, ok := old.(*DRCluster)
4142
if !ok {
42-
return fmt.Errorf("error casting old DRCluster")
43+
return nil, fmt.Errorf("error casting old DRCluster")
4344
}
4445

4546
// check for immutability for Region and S3ProfileName
4647
if r.Spec.Region != oldDRCluster.Spec.Region {
47-
return fmt.Errorf("Region cannot be changed")
48+
return nil, fmt.Errorf("Region cannot be changed")
4849
}
4950

5051
if r.Spec.S3ProfileName != oldDRCluster.Spec.S3ProfileName {
51-
return fmt.Errorf("S3ProfileName cannot be changed")
52+
return nil, fmt.Errorf("S3ProfileName cannot be changed")
5253
}
5354

5455
return r.ValidateDRCluster()
5556
}
5657

5758
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
58-
func (r *DRCluster) ValidateDelete() error {
59+
func (r *DRCluster) ValidateDelete() (admission.Warnings, error) {
5960
drclusterlog.Info("validate delete", "name", r.Name)
6061

61-
return nil
62+
return nil, nil
6263
}
6364

64-
func (r *DRCluster) ValidateDRCluster() error {
65+
func (r *DRCluster) ValidateDRCluster() (admission.Warnings, error) {
6566
if r.Spec.Region == "" {
66-
return fmt.Errorf("Region cannot be empty")
67+
return nil, fmt.Errorf("Region cannot be empty")
6768
}
6869

6970
if r.Spec.S3ProfileName == "" {
70-
return fmt.Errorf("S3ProfileName cannot be empty")
71+
return nil, fmt.Errorf("S3ProfileName cannot be empty")
7172
}
7273

7374
// TODO: We can add other validations like validation of CIDRs format
7475

75-
return nil
76+
return nil, nil
7677
}

api/v1alpha1/drplacementcontrol_webhook.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
ctrl "sigs.k8s.io/controller-runtime"
1212
logf "sigs.k8s.io/controller-runtime/pkg/log"
1313
"sigs.k8s.io/controller-runtime/pkg/webhook"
14+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1415
)
1516

1617
// log is for logging in this package.
@@ -28,19 +29,19 @@ func (r *DRPlacementControl) SetupWebhookWithManager(mgr ctrl.Manager) error {
2829
var _ webhook.Validator = &DRPlacementControl{}
2930

3031
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
31-
func (r *DRPlacementControl) ValidateCreate() error {
32+
func (r *DRPlacementControl) ValidateCreate() (admission.Warnings, error) {
3233
drplacementcontrollog.Info("validate create", "name", r.Name)
3334

34-
return nil
35+
return nil, nil
3536
}
3637

3738
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
38-
func (r *DRPlacementControl) ValidateUpdate(old runtime.Object) error {
39+
func (r *DRPlacementControl) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
3940
drplacementcontrollog.Info("validate update", "name", r.Name)
4041

4142
oldDRPC, ok := old.(*DRPlacementControl)
4243
if !ok {
43-
return fmt.Errorf("error casting old DRPC")
44+
return nil, fmt.Errorf("error casting old DRPC")
4445
}
4546

4647
// checks for immutability
@@ -49,31 +50,31 @@ func (r *DRPlacementControl) ValidateUpdate(old runtime.Object) error {
4950
"old", oldDRPC.Spec.PlacementRef,
5051
"new", r.Spec.PlacementRef)
5152

52-
return fmt.Errorf("PlacementRef cannot be changed")
53+
return nil, fmt.Errorf("PlacementRef cannot be changed")
5354
}
5455

5556
if !reflect.DeepEqual(r.Spec.DRPolicyRef, oldDRPC.Spec.DRPolicyRef) {
5657
drplacementcontrollog.Info("detected DRPolicyRef updates, which is disallowed", "name", r.Name,
5758
"old", oldDRPC.Spec.DRPolicyRef,
5859
"new", r.Spec.DRPolicyRef)
5960

60-
return fmt.Errorf("DRPolicyRef cannot be changed")
61+
return nil, fmt.Errorf("DRPolicyRef cannot be changed")
6162
}
6263

6364
if !reflect.DeepEqual(r.Spec.PVCSelector, oldDRPC.Spec.PVCSelector) {
6465
drplacementcontrollog.Info("detected PVCSelector updates, which is disallowed", "name", r.Name,
6566
"old", oldDRPC.Spec.PVCSelector,
6667
"new", r.Spec.PVCSelector)
6768

68-
return fmt.Errorf("PVCSelector cannot be changed")
69+
return nil, fmt.Errorf("PVCSelector cannot be changed")
6970
}
7071

71-
return nil
72+
return nil, nil
7273
}
7374

7475
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
75-
func (r *DRPlacementControl) ValidateDelete() error {
76+
func (r *DRPlacementControl) ValidateDelete() (admission.Warnings, error) {
7677
drplacementcontrollog.Info("validate delete", "name", r.Name)
7778

78-
return nil
79+
return nil, nil
7980
}

api/v1alpha1/drpolicy_webhook.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
ctrl "sigs.k8s.io/controller-runtime"
1212
logf "sigs.k8s.io/controller-runtime/pkg/log"
1313
"sigs.k8s.io/controller-runtime/pkg/webhook"
14+
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
1415
)
1516

1617
// log is for logging in this package.
@@ -28,45 +29,45 @@ func (r *DRPolicy) SetupWebhookWithManager(mgr ctrl.Manager) error {
2829
var _ webhook.Validator = &DRPolicy{}
2930

3031
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
31-
func (r *DRPolicy) ValidateCreate() error {
32+
func (r *DRPolicy) ValidateCreate() (admission.Warnings, error) {
3233
drpolicylog.Info("validate create", "name", r.Name)
3334

34-
return nil
35+
return nil, nil
3536
}
3637

3738
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
38-
func (r *DRPolicy) ValidateUpdate(old runtime.Object) error {
39+
func (r *DRPolicy) ValidateUpdate(old runtime.Object) (admission.Warnings, error) {
3940
drpolicylog.Info("validate update", "name", r.Name)
4041

4142
oldDRPolicy, ok := old.(*DRPolicy)
4243

4344
if !ok {
44-
return fmt.Errorf("error casting old DRPolicy")
45+
return nil, fmt.Errorf("error casting old DRPolicy")
4546
}
4647

4748
// checks for immutability
4849
if r.Spec.SchedulingInterval != oldDRPolicy.Spec.SchedulingInterval {
49-
return fmt.Errorf("SchedulingInterval cannot be changed")
50+
return nil, fmt.Errorf("SchedulingInterval cannot be changed")
5051
}
5152

5253
if !reflect.DeepEqual(r.Spec.ReplicationClassSelector, oldDRPolicy.Spec.ReplicationClassSelector) {
53-
return fmt.Errorf("ReplicationClassSelector cannot be changed")
54+
return nil, fmt.Errorf("ReplicationClassSelector cannot be changed")
5455
}
5556

5657
if !reflect.DeepEqual(r.Spec.VolumeSnapshotClassSelector, oldDRPolicy.Spec.VolumeSnapshotClassSelector) {
57-
return fmt.Errorf("VolumeSnapshotClassSelector cannot be changed")
58+
return nil, fmt.Errorf("VolumeSnapshotClassSelector cannot be changed")
5859
}
5960

6061
if !reflect.DeepEqual(r.Spec.DRClusters, oldDRPolicy.Spec.DRClusters) {
61-
return fmt.Errorf("DRClusters cannot be changed")
62+
return nil, fmt.Errorf("DRClusters cannot be changed")
6263
}
6364

64-
return nil
65+
return nil, nil
6566
}
6667

6768
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
68-
func (r *DRPolicy) ValidateDelete() error {
69+
func (r *DRPolicy) ValidateDelete() (admission.Warnings, error) {
6970
drpolicylog.Info("validate delete", "name", r.Name)
7071

71-
return nil
72+
return nil, nil
7273
}

api/v1alpha1/volumereplicationgroup_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ type ProtectedPVC struct {
258258

259259
// Resources set in the claim to be replicated
260260
//+optional
261-
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
261+
Resources corev1.VolumeResourceRequirements `json:"resources,omitempty"`
262262

263263
// Conditions for this protected pvc
264264
//+optional

api/v1alpha1/zz_generated.deepcopy.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)