Skip to content
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

feat: Nullable logic in code #1261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
48 changes: 0 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
# Commenting out default which overwrites scoped config/rbac/role.yaml
# GOFLAGS="-mod=mod" $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
GOFLAGS="-mod=mod" $(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# run make nullables to generate nullable fields after all manifest changesin dependent targets.
# It's not included here because `test` and `bundle` target have different yaml styes.
# To keep dpa CRD the same, nullables have been added to test and bundle target separately.

generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
GOFLAGS="-mod=mod" $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand Down Expand Up @@ -291,11 +288,6 @@ rm -rf $$TMP_DIR ;\
}
endef

YQ = $(shell pwd)/bin/yq
yq: ## Download yq locally if necessary.
# 4.28.1 is latest with go 1.17 go.mod
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/[email protected])

OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
operator-sdk:
# Download operator-sdk locally if does not exist
Expand All @@ -310,51 +302,11 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
GOFLAGS="-mod=mod" $(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && GOFLAGS="-mod=mod" $(KUSTOMIZE) edit set image controller=$(IMG)
GOFLAGS="-mod=mod" $(KUSTOMIZE) build config/manifests | GOFLAGS="-mod=mod" $(OPERATOR_SDK) generate bundle -q --extra-service-accounts "velero" --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
@make nullables
# Copy updated bundle.Dockerfile to CI's Dockerfile.bundle
# TODO: update CI to use generated one
cp bundle.Dockerfile build/Dockerfile.bundle
GOFLAGS="-mod=mod" $(OPERATOR_SDK) bundle validate ./bundle

.PHONY: nullables
nullables:
@make nullable-crds-bundle nullable-crds-config # patch nullables in CRDs

.PHONY: nullable-crds-bundle
nullable-crds-bundle: DPA_SPEC_CONFIG_PROP = .spec.versions.0.schema.openAPIV3Schema.properties.spec.properties.configuration.properties
nullable-crds-bundle: PROP_RESOURCE_ALLOC = properties.podConfig.properties.resourceAllocations
nullable-crds-bundle: VELERO_RESOURCE_ALLOC = $(DPA_SPEC_CONFIG_PROP).velero.$(PROP_RESOURCE_ALLOC)
nullable-crds-bundle: RESTIC_RESOURCE_ALLOC = $(DPA_SPEC_CONFIG_PROP).restic.$(PROP_RESOURCE_ALLOC)
nullable-crds-bundle: DPA_CRD_YAML ?= bundle/manifests/oadp.openshift.io_dataprotectionapplications.yaml
nullable-crds-bundle: yq
# Velero CRD
@$(YQ) '$(VELERO_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.limits.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.limits.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.requests.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.requests.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
# Restic CRD
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.limits.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.limits.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.requests.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.requests.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)

.PHONY: nullable-crds-config
nullable-crds-config: DPA_CRD_YAML ?= config/crd/bases/oadp.openshift.io_dataprotectionapplications.yaml
nullable-crds-config:
@ DPA_CRD_YAML=$(DPA_CRD_YAML) make nullable-crds-bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . $(DOCKER_BUILD_ARGS)
Expand Down
18 changes: 17 additions & 1 deletion api/v1alpha1/oadp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ type VeleroConfig struct {
Args *server.Args `json:"args,omitempty"`
}

// Copy of corev1.ResourceRequirements with nullable
type OADPResourceRequirements struct {
// Limits describes the maximum amount of compute resources allowed.
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
// +nullable
Limits corev1.ResourceList `json:"limits,omitempty" protobuf:"bytes,1,rep,name=limits,casttype=ResourceList,castkey=ResourceName"`
// Requests describes the minimum amount of compute resources required.
// If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
// otherwise to an implementation-defined value.
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
// +optional
// +nullable
Requests corev1.ResourceList `json:"requests,omitempty" protobuf:"bytes,2,rep,name=requests,casttype=ResourceList,castkey=ResourceName"`
}

// PodConfig defines the pod configuration options
type PodConfig struct {
// labels to add to pods
Expand All @@ -115,7 +131,7 @@ type PodConfig struct {
// resourceAllocations defines the CPU and Memory resource allocations for the Pod
// +optional
// +nullable
ResourceAllocations corev1.ResourceRequirements `json:"resourceAllocations,omitempty"`
ResourceAllocations OADPResourceRequirements `json:"resourceAllocations,omitempty"`
// env defines the list of environment variables to be supplied to podSpec
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`
Expand Down
29 changes: 29 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading