Skip to content
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
30 changes: 24 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore everything by default and re-include only needed files
**
# Ignore build artifacts and unnecessary files
bin/
testbin/
*.test
*.out
coverage.out

# Re-include Go source files (but not *_test.go)
!**/*.go
# Ignore git and IDE files
.git
.gitignore
.idea
.vscode
*.swp
*.swo

# Ignore documentation
*.md
docs/

# Ignore CI/CD files
.github/

# Ignore test binaries
**/*_test.go

# Re-include Go module files
# Re-include essential files
!go.mod
!go.sum
!go.sum
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ COPY . .
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager /workspace/cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
COPY --from=builder /workspace/templates .
USER 1001:1001

ENTRYPOINT ["/manager"]

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ endif
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
CONTAINER_TOOL ?= podman

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
Expand Down
19 changes: 1 addition & 18 deletions api/v1alpha1/nodeswap_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type KubeSwapMode string

const (
KubeSwapLimited KubeSwapMode = "Limited"
KubeSwapUnlimited KubeSwapMode = "Unlimited"
)

// KubeletConfig defines swap related configuration for kubelet
type KubeletConfig struct {
// +kubebuilder:validation:Type=string
SwapMode KubeSwapMode `json:"swapMode,omitempty"`
}

type SwapType string

const (
Expand Down Expand Up @@ -82,13 +69,9 @@ type NodeSwapSpec struct {
// More info: https://book.kubebuilder.io/reference/markers/crd-validation.html

// Label selector for Machines on which swap will be deployed.
NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty"`
MachineConfigPoolSelector string `json:"machineConfigPoolSelector,omitempty"`

Swaps Swaps `json:"swaps,omitempty"`

// +optional
KubeletConfig *KubeletConfig `json:"kubeletConfig,omitempty"`

// +optional
LogLevel *int32 `json:"logLevel,omitempty"`
}
Expand Down
25 changes: 0 additions & 25 deletions api/v1alpha1/zz_generated.deepcopy.go

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

17 changes: 15 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ import (

nodeswapv1alpha1 "github.com/openshift-virtualization/swap-operator/api/v1alpha1"
"github.com/openshift-virtualization/swap-operator/internal/controller"
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
// +kubebuilder:scaffold:imports
)

var templateDir string

var (
scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand All @@ -49,6 +52,8 @@ func init() {
utilruntime.Must(clientgoscheme.AddToScheme(scheme))

utilruntime.Must(nodeswapv1alpha1.AddToScheme(scheme))

utilruntime.Must(mcfgv1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
}

Expand Down Expand Up @@ -76,6 +81,7 @@ func main() {
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
flag.StringVar(&templateDir, "template-dir", "/templates", "The directory that contains the templates.")
flag.StringVar(&metricsCertKey, "metrics-cert-key", "tls.key", "The name of the metrics server key file.")
flag.BoolVar(&enableHTTP2, "enable-http2", false,
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
Expand All @@ -87,6 +93,12 @@ func main() {

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

// Validate template directory exists
if _, err := os.Stat(templateDir); err != nil {
panic(err)
}
setupLog.Info("validated template directory", "path", templateDir)

// if the enable-http2 flag is false (the default), http/2 should be disabled
// due to its vulnerabilities. More specifically, disabling http/2 will
// prevent from being vulnerable to the HTTP/2 Stream Cancellation and
Expand Down Expand Up @@ -179,8 +191,9 @@ func main() {
}

if err := (&controller.NodeSwapReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
TemplateDir: templateDir, // Add this line
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "NodeSwap")
os.Exit(1)
Expand Down
54 changes: 2 additions & 52 deletions config/crd/bases/node-swap.openshift.io_nodeswaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,62 +39,12 @@ spec:
spec:
description: NodeSwapSpec defines the desired state of NodeSwap
properties:
kubeletConfig:
description: KubeletConfig defines swap related configuration for
kubelet
properties:
swapMode:
type: string
type: object
logLevel:
format: int32
type: integer
nodeSelector:
machineConfigPoolSelector:
description: Label selector for Machines on which swap will be deployed.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
type: string
swaps:
items:
properties:
Expand Down
Loading
Loading