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

Add "cis "to the cis-profile enum to support 1.29+ #301

Merged
merged 3 commits into from
Aug 26, 2024
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
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export PATH := $(KREW_ROOT)/bin:$(PATH)

# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(ROOT_DIR)),$(shell go env GOPATH)/src/github.com/rancher/cluster-api-provider-rke2)
CONVERSION_GEN_OUTPUT_BASE_CAPRKE2 := --output-base=$(ROOT_DIR)/$(CAPRKE2_DIR)
CONVERSION_GEN_OUTPUT_BASE_CAPBPR := --output-base=$(ROOT_DIR)/$(CAPBPR_DIR)
CONVERSION_GEN_OUTPUT_BASE_CAPRKE2 := --output-dir=$(ROOT_DIR)/$(CAPRKE2_DIR)
CONVERSION_GEN_OUTPUT_BASE_CAPBPR := --output-dir=$(ROOT_DIR)/$(CAPBPR_DIR)
else
export GOPATH := $(shell go env GOPATH)
endif
Expand All @@ -77,7 +77,7 @@ CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen

CONVERSION_GEN_VER := v0.28.0
CONVERSION_GEN_VER := v0.30.0
CONVERSION_GEN_BIN := conversion-gen
# We are intentionally using the binary without version suffix, to avoid the version
# in generated files.
Expand Down Expand Up @@ -210,20 +210,18 @@ generate-go-conversions: ## Run all generate-go-conversions-* targets
generate-go-conversions-rke2-bootstrap: $(CONVERSION_GEN) ## Generate conversions go code for the rke2 bootstrap
$(MAKE) clean-generated-conversions SRC_DIRS="./bootstrap/api/v1alpha1"
$(CONVERSION_GEN) \
--input-dirs=./bootstrap/api/v1alpha1 \
--build-tag=ignore_autogenerated_rke2_bootstrap \
--output-file-base=zz_generated.conversion $(ROOT_DIR) \
--go-header-file=./hack/boilerplate.go.txt
--output-file=zz_generated.conversion.go $(ROOT_DIR)/$(CAPBPR_DIR) \
--go-header-file=./hack/boilerplate.go.txt \
./bootstrap/api/v1alpha1

.PHONY: generate-go-conversions-rke2-control-plane
generate-go-conversions-rke2-control-plane: $(CONVERSION_GEN) ## Generate conversions go code for the rke2 control plane
$(MAKE) clean-generated-conversions SRC_DIRS="./controlplane/api/v1alpha1"
$(CONVERSION_GEN) \
--input-dirs=./controlplane/api/v1alpha1 \
--extra-peer-dirs=github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1alpha1 \
--build-tag=ignore_autogenerated_rk2_control_plane \
--output-file-base=zz_generated.conversion $(ROOT_DIR) \
--go-header-file=./hack/boilerplate.go.txt
--extra-dirs=github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1alpha1 \
--output-file=zz_generated.conversion.go $(ROOT_DIR)/$(CAPRKE2_DIR) \
Copy link
Contributor

@hardys hardys Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the --build-tag here need to be removed like the bootstrap?

make generate works for me locally with that removed, and we can see unknown flag: --build-tag in the CI results

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated 👍

--go-header-file=./hack/boilerplate.go.txt \
./controlplane/api/v1alpha1

.PHONY: generate-modules
generate-modules: ## Run go mod tidy to ensure modules are up to date
Expand Down
5 changes: 4 additions & 1 deletion bootstrap/api/v1alpha1/rke2config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type RKE2AgentConfig struct {
Snapshotter string `json:"snapshotter,omitempty"`

// CISProfile activates CIS compliance of RKE2 for a certain profile
// +kubebuilder:validation:Enum=cis-1.23;cis-1.5;cis-1.6
// +kubebuilder:validation:Enum=cis;cis-1.23;cis-1.5;cis-1.6
//+optional
CISProfile CISProfile `json:"cisProfile,omitempty"`

Expand Down Expand Up @@ -256,6 +256,9 @@ type RKE2ConfigList struct {
type CISProfile string

const (
// CIS references RKE2's CIS Profile "cis".
CIS CISProfile = "cis"

// CIS1_23 references RKE2's CIS Profile "cis-1.23".
CIS1_23 CISProfile = "cis-1.23"

Expand Down
4 changes: 2 additions & 2 deletions bootstrap/api/v1alpha1/zz_generated.conversion.go

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

2 changes: 1 addition & 1 deletion bootstrap/api/v1alpha1/zz_generated.deepcopy.go

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

5 changes: 4 additions & 1 deletion bootstrap/api/v1beta1/rke2config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type RKE2AgentConfig struct {
Snapshotter string `json:"snapshotter,omitempty"`

// CISProfile activates CIS compliance of RKE2 for a certain profile
// +kubebuilder:validation:Enum=cis-1.23;cis-1.5;cis-1.6
// +kubebuilder:validation:Enum=cis;cis-1.23;cis-1.5;cis-1.6
//+optional
CISProfile CISProfile `json:"cisProfile,omitempty"`

Expand Down Expand Up @@ -257,6 +257,9 @@ type RKE2ConfigList struct {
type CISProfile string

const (
// CIS references RKE2's CIS Profile "cis".
CIS CISProfile = "cis"

// CIS1_23 references RKE2's CIS Profile "cis-1.23".
CIS1_23 CISProfile = "cis-1.23"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2 for a
certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down Expand Up @@ -665,6 +666,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2 for a
certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2
for a certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down Expand Up @@ -640,6 +641,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2
for a certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down
10 changes: 10 additions & 0 deletions controlplane/api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
apiconversion "k8s.io/apimachinery/pkg/conversion"
utilconversion "sigs.k8s.io/cluster-api/util/conversion"

bootstrapv1beta1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta1"
bootstrapv1alpha1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1alpha1"
controlplanev1 "github.com/rancher/cluster-api-provider-rke2/controlplane/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/conversion"
)
Expand Down Expand Up @@ -202,3 +204,11 @@ func Convert_v1alpha1_RKE2ControlPlaneTemplateStatus_To_v1beta1_RKE2ControlPlane
func Convert_v1beta1_RKE2ControlPlaneStatus_To_v1alpha1_RKE2ControlPlaneTemplateStatus(in *controlplanev1.RKE2ControlPlaneStatus, out *RKE2ControlPlaneTemplateStatus, s apiconversion.Scope) error {
return nil
}

func Convert_v1beta1_RKE2ConfigSpec_To_v1alpha1_RKE2ConfigSpec(in *bootstrapv1beta1.RKE2ConfigSpec, out *bootstrapv1alpha1.RKE2ConfigSpec, s apiconversion.Scope) error {
return bootstrapv1alpha1.Convert_v1beta1_RKE2ConfigSpec_To_v1alpha1_RKE2ConfigSpec(in, out, s)
}

func Convert_v1alpha1_RKE2ConfigSpec_To_v1beta1_RKE2ConfigSpec(in *bootstrapv1alpha1.RKE2ConfigSpec, out *bootstrapv1beta1.RKE2ConfigSpec, s apiconversion.Scope) error {
return bootstrapv1alpha1.Convert_v1alpha1_RKE2ConfigSpec_To_v1beta1_RKE2ConfigSpec(in, out, s)
}
118 changes: 24 additions & 94 deletions controlplane/api/v1alpha1/zz_generated.conversion.go

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

2 changes: 1 addition & 1 deletion controlplane/api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2 for a
certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down Expand Up @@ -1310,6 +1311,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2 for a
certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ spec:
description: CISProfile activates CIS compliance of RKE2
for a certain profile
enum:
- cis
- cis-1.23
- cis-1.5
- cis-1.6
Expand Down
2 changes: 1 addition & 1 deletion pkg/rke2/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ var _ = Describe("RKE2 Agent Config", func() {
LoadBalancerPort: 1234,
NodeLabels: []string{"testlabel"},
NodeTaints: []string{"testtaint"},
CISProfile: bootstrapv1.CIS1_23, //nolint:nosnakecase
CISProfile: bootstrapv1.CIS, //nolint:nosnakecase
ProtectKernelDefaults: true,
ResolvConf: &corev1.ObjectReference{
Name: "test",
Expand Down
2 changes: 2 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ func ProfileCompliant(profile bootstrapv1.CISProfile, version string) bool {
}

switch profile {
case bootstrapv1.CIS:
return isAtLeastv125
case bootstrapv1.CIS1_23:
return isAtLeastv125
case bootstrapv1.CIS1_5:
Expand Down