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

Initial code add #1

Merged
merged 15 commits into from
Jan 5, 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
56 changes: 56 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
Thank you for contributing to CSA! Please provide all details requested below prior to submitting your pull request
(PR).

# Important Information
- We don't formalize coding standards for this project, but please try to use the existing code as a convention guide.
- CSA and the Helm chart adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - please be aware of this
when incrementing versions.
- Releases of CSA and the Helm chart are managed independently of merging to `main` - a maintainer will prepare
release(s) for you post-merge.

# Areas Affected by PR
Please indicate what areas are affected by your PR (check all that apply):

- [ ] CSA
- [ ] Helm chart

# Nature of PR
Please indicate the nature of your PR (check all that apply):

- [ ] New feature
- [ ] Bug fix
- [ ] Security
- [ ] Other (please provide details within the description)

# Issue Links
Please link to any issues related to your PR, or indicate if not applicable.

# Description
Please provide a description of the change(s) contained within your PR here.

# Checklist
Please ensure you work through any of **applicable** items below prior to submitting your PR:

## Commits
- [ ] Commits are of logical units (to help us work through your changes)

## Tests
- [ ] New unit/integration tests are implemented
- [ ] Existing unit/integration tests are updated
- [ ] All unit/integration tests are passing

## Sandbox Scripts
- [ ] Sandbox scripts are updated

## Docs
- [ ] `README.md` is updated
- [ ] `CHANGELOG.md` is updated

## Helm Chart
- [ ] New tests are implemented
- [ ] Existing tests are updated
- [ ] All tests are passing
- [ ] `version` within `Chart.yaml` is incremented (only if changes made to CSA or the chart itself)
- [ ] `appVersion` within `Chart.yaml` is incremented (only if changes made to CSA)
- [ ] `README.md` is updated
- [ ] `CHANGELOG.md` is updated
33 changes: 33 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CodeQL

on:
pull_request:
branches: ["main"]
push:
branches:
- main
schedule:
- cron: '0 0 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: go
queries: security-extended

- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
99 changes: 99 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Release

on:
push:
tags:
- 'csa-*'

jobs:
validate-tag:
name: Validate tag
runs-on: ubuntu-latest

steps:
- name: Validate tag
run: |
if ! [[ "$GITHUB_REF_NAME" =~ ^csa-[0-9]+.[0-9]+.[0-9]+$ ]]; then
echo "Tag does not match expected pattern - got $GITHUB_REF_NAME"
exit 1
fi

publish-docker-image:
name: Publish Docker image
runs-on: ubuntu-latest
needs: validate-tag

steps:
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: expediagroup/container-startup-autoscaler
tags: |
type=match,pattern=csa-(.*),group=1

- name: Docker setup QEMU
uses: docker/setup-qemu-action@v3

- name: Docker setup buildx
uses: docker/setup-buildx-action@v3

- name: Docker Hub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}

- name: Docker build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

publish-helm-chart:
name: Publish Helm chart
runs-on: ubuntu-latest
needs: publish-docker-image

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.13.1

- name: Install chart-releaser
uses: helm/chart-releaser-action@v1.5.0
with:
install_only: true

- name: Run chart-releaser
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
CR_RELEASE_NAME_TEMPLATE: "chart-{{ .Version }}"
run: |
owner=$(cut -d '/' -f 1 <<< "$GITHUB_REPOSITORY")
repo=$(cut -d '/' -f 2 <<< "$GITHUB_REPOSITORY")

git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

rm -rf .cr-release-packages
rm -rf .cr-index
mkdir -p .cr-release-packages
mkdir -p .cr-index

cr package charts/container-startup-autoscaler

# https://github.com/helm/chart-releaser#create-github-releases-from-helm-chart-packages
cr upload -o "$owner" -r "$repo" -c "$(git rev-parse HEAD)" --skip-existing \
--release-notes-file=releasenotes.md --make-release-latest=false

# https://github.com/helm/chart-releaser#create-the-repository-index-from-github-releases
cr index -o "$owner" -r "$repo" --push
64 changes: 64 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Tests

on:
pull_request:
branches: [ "main" ]

jobs:
unit:
name: Run unit tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Test
run: make test-run-unit

integration:
name: Run integration tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Set up Kind
uses: helm/kind-action@v1.8.0
with:
install_only: true
version: v0.20.0
kubectl_version: v1.27.2

- name: Test
env:
MAX_PARALLELISM: 1 # Constrained to 2 CPUs on ubuntu-latest
run: make test-run-int-verbose

helm:
name: Run Helm tests
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Test
run: make test-run-helm
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog
- Based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.0
2024-01-05

### Added
- Initial version.

### Helm Chart
[1.0.0](charts/container-startup-autoscaler/CHANGELOG.md#100)

### Kubernetes Compatibility
| Kube Version | Compatible? | `In-place Update of Pod Resources` Maturity |
|:------------:|:-----------:|:-------------------------------------------:|
| 1.29 | ✔️ | Alpha |
| 1.28 | ✔️ | Alpha |
| 1.27 | ❌ | Alpha |
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing
If you'd like to contribute code, please fork this GitHub repository, create a branch, and open a pull request. Please
provide all details requested within the pull request template. A maintainer will review your submission.
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2024 Expedia Group, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM --platform=$BUILDPLATFORM golang:1.21 AS build

ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH
RUN echo "Build platform: $BUILDPLATFORM, target platform: $TARGETPLATFORM, target OS: $TARGETOS, target arch: $TARGETARCH"

RUN openssl s_client -showcerts -connect proxy.golang.org:443 </dev/null 2>/dev/null|openssl x509 -outform PEM > /usr/local/share/ca-certificates/goproxy.crt
RUN update-ca-certificates

WORKDIR /csa
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY cmd ./cmd
COPY internal ./internal

RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-w -s" -o ./csa ./cmd/container-startup-autoscaler

FROM --platform=$TARGETPLATFORM scratch

COPY --from=build /csa/csa /csa/csa
EXPOSE 8080/tcp
EXPOSE 8081/tcp
EXPOSE 8082/tcp
ENTRYPOINT ["/csa/csa"]
Loading