Skip to content

Commit

Permalink
Poc (#1)
Browse files Browse the repository at this point in the history
It works with minikube!
  • Loading branch information
dmolik authored Jul 31, 2024
1 parent 1f26ae8 commit 3fe96e4
Show file tree
Hide file tree
Showing 73 changed files with 14,963 additions and 43 deletions.
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
19 changes: 19 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Go Build

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: 1.22
# You can test your matrix by printing the current Go version
- name: Display Go version
run: go version
- name: Build it
run: make V=1
74 changes: 74 additions & 0 deletions .github/workflows/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Create and publish a Docker image

on:
push:
tags:
- '*'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read # for trivy scan upload
packages: write
id-token: write
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ env.RELEASE_VERSION }}

- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: 1.22
# You can test your matrix by printing the current Go version
- name: Display Go version
run: go version
- name: Build it
run: make V=1

- name: Build and push Docker image
uses: docker/build-push-action@5176d81f87c23d6fc96624dfdbcd9f3830bbe445
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}${{ env.RELEASE_VERSION }}'
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
#env:
# GITHUB_TOKEN: ${{ secrets.TOKEN }}
65 changes: 65 additions & 0 deletions .github/workflows/scan.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Scan

# Run workflow each time code is pushed to your repository and on a schedule.
# The scheduled workflow runs every at 00:00 on Sunday UTC time.
on:
push:
branches:
- main
pull_request:

jobs:
hadolint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: hadolint/[email protected]
with:
dockerfile: Dockerfile
gosec:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Security Scan
uses: securego/gosec@master
with:
# we let the report trigger content trigger a failure using the GitHub Security features.
args: '-fmt sarif -out results.sarif ./...'
- name: Upload SARIF file
if: always()
uses: github/codeql-action/upload-sarif@v3
with:
# Path to SARIF file relative to the root of the repository
sarif_file: results.sarif
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.57

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
args: --timeout=5m --config=.golangci.yml

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ go.work
*.swp
*.swo
*~

.cni-north.yaml
.coredns.yaml
.ingress.yaml
blank.yaml
cilium/
manager
26 changes: 13 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# Build the manager binary
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH
#FROM golang:1.22 AS builder
#ARG TARGETOS
#ARG TARGETARCH

WORKDIR /workspace
#WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
#COPY go.mod go.mod
#COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
#RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
#COPY cmd/main.go cmd/main.go
#COPY api/ api/
#COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# 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 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 .
#WORKDIR /
COPY manager /manager
USER 65532:65532

ENTRYPOINT ["/manager"]
40 changes: 36 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ else
GOBIN=$(shell go env GOBIN)
endif

GO := $(shell which go)
MINIKUBE := $(shell which minikube)
KUBECTL := $(shell which kubectl)

# CONTAINER_TOOL defines the container tool to be used for building images.
# 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
Expand All @@ -21,6 +25,18 @@ CONTAINER_TOOL ?= docker
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

K8S_VERSION ?= 1.30.3
CILIUM_VERSION ?= 1.16.0

V ?= 0
ifeq ($(V), 1)
Q =
VV = -v
else
Q = @
VV =
endif

.PHONY: all
all: build

Expand Down Expand Up @@ -78,9 +94,15 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes

##@ Build

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go
manager: manifests generate fmt vet ## Build manager binary.
$QCGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build $(VV) \
-trimpath \
-gcflags all="-trimpath=/src -trimpath=$(PWD)" \
-asmflags all="-trimpath=/src -trimpath=$(PWD)" \
-installsuffix cgo \
-o $@ cmd/main.go

build: manager

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand All @@ -90,7 +112,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker-build: manager ## Build docker image with the manager.
$(CONTAINER_TOOL) build -t ${IMG} .

.PHONY: docker-push
Expand Down Expand Up @@ -163,6 +185,16 @@ CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.57.2

.PHONY: minikube tunnel proxy
minikube: ## Spool up a local minikube cluster for development
$QK8S_VERSION=$(K8S_VERSION) CILIUM_VERSION=$(CILIUM_VERSION) scripts/minikube.sh

tunnel: ## turn on minikube's tunnel to test ingress and get UI access
$Q$(MINIKUBE) tunnel -p north

proxy: ## turn on a port to push locally built containers into the cluster
$Q$(KUBECTL) port-forward --namespace kube-system service/registry 5000:80

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
Expand Down
54 changes: 54 additions & 0 deletions config/crd/bases/hyperspike.io_valkeys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.15.0
name: valkeys.hyperspike.io
spec:
group: hyperspike.io
names:
kind: Valkey
listKind: ValkeyList
plural: valkeys
singular: valkey
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: Valkey is the Schema for the valkeys API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: ValkeySpec defines the desired state of Valkey
properties:
foo:
description: Foo is an example field of Valkey. Edit valkey_types.go
to remove/update
type: string
type: object
status:
description: ValkeyStatus defines the observed state of Valkey
type: object
type: object
served: true
storage: true
subresources:
status: {}
6 changes: 6 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
resources:
- manager.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: localhost:5000/controller
newTag: "1"
Loading

0 comments on commit 3fe96e4

Please sign in to comment.