Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: makocchi-git <[email protected]>
  • Loading branch information
makocchi-git committed Jun 3, 2024
1 parent 3cd6546 commit a5dd74b
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 337 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ jobs:
with:
go-version-file: go.mod
- run: make test
- uses: shogo82148/actions-goveralls@v1
- uses: shogo82148/actions-goveralls@7b1bd2871942af030d707d6574e5f684f9891fb2 # v1.8.0
with:
path-to-profile: cover.out
2 changes: 1 addition & 1 deletion .github/workflows/docker_nightly_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- uses: docker/build-push-action@v5
with:
push: true
tags: docker.pkg.github.com/ubie-oss/cluster-lending-manager/controller:latest
tags: docker.pkg.github.com/ubie-oss/cluster-lending-manager/cluster-lending-manager-controller:latest
25 changes: 0 additions & 25 deletions .github/workflows/docker_release.yaml

This file was deleted.

47 changes: 47 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Docker image and manifests
on:
push:
tags:
- 'v*'
jobs:
push_to_registry:
name: Push Docker image to GitHub Docker Registry
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v2
with:
registry: docker.pkg.github.com
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: docker.pkg.github.com/ubie-oss/cluster-lending-manager/cluster-lending-manager-controller
- name: Build container image
uses: docker/build-push-action@v5
with:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release-manifest:
name: Release manifest
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Set up kustomize
uses: imranismail/setup-kustomize@2ba527d4d055ab63514ba50a99456fc35684947f # v2.1.0
- name: kustomize build
run: kustomize build config/crd > cluster-lending-manager-crd.yaml
- name: Release
uses: softprops/action-gh-release@69320dbe05506a9a39fc8ae11030b214ec2d1f87 # v2.0.5
with:
files: |
cluster-lending-manager-crd.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

# Image URL to use all building/pushing image targets
IMG ?= docker.pkg.github.com/ubie-oss/cluster-lending-manager/controller:latest
IMG ?= ghcr.io/ubie-oss/cluster-lending-manager/cluster-lending-manager-controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23
ENVTEST_K8S_VERSION = 1.29

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -121,28 +121,28 @@ undeploy-samples:
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v5.0.1)

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-get-tool will 'go get' any package $2 and install it to $1.
# go-install-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ClusterLendingManager

CronHPA was created by [dtaniwaki](https://github.com/dtaniwaki/cluster-lending-manager). We forked because the original version is no longer being actively maintained.
ClusterLendingManager was created by [dtaniwaki](https://github.com/dtaniwaki/cluster-lending-manager). We forked because the original version is no longer being actively maintained.

[![Go Reference][godoc-image]][godoc-link]
[![Coverage Status][cov-image]][cov-link]
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the clusterlendingmanager v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=clusterlendingmanager.ubie-oss.github.com
// +kubebuilder:object:generate=true
// +groupName=clusterlendingmanager.ubie-oss.github.com
package v1alpha1

import (
Expand Down
80 changes: 41 additions & 39 deletions api/v1alpha1/lendingconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,100 +20,101 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Schedule is ...
// Schedule represents a time schedule with a start and end time.
type Schedule struct {
// Start is ...
// Start is the start time of the schedule.
Start *string `json:"start,omitempty"`
// End is ...
// End is the end time of the schedule.
End *string `json:"end,omitempty"`
}

// DaySchedule is ...
// DaySchedule represents a schedule for a specific day, consisting of multiple time schedules.
type DaySchedule struct {
// Hours is ...
// Hours is a list of time schedules for the day.
Hours []Schedule `json:"hours,omitempty"`
}

// Schedule is ...
// ScheduleSpec represents the schedule specification for a lending configuration.
type ScheduleSpec struct {
// Default is ...
// Default is the default schedule for all days.
Default *DaySchedule `json:"default,omitempty"`
// Monday is ...
// Monday is the schedule for Monday.
Monday *DaySchedule `json:"monday,omitempty"`
// Tuesday is ...
// Tuesday is the schedule for Tuesday.
Tuesday *DaySchedule `json:"tuesday,omitempty"`
// Wednesday is ...
// Wednesday is the schedule for Wednesday.
Wednesday *DaySchedule `json:"wednesday,omitempty"`
// Thursday is ...
// Thursday is the schedule for Thursday.
Thursday *DaySchedule `json:"thursday,omitempty"`
// Friday is ...
// Friday is the schedule for Friday.
Friday *DaySchedule `json:"friday,omitempty"`
// Saturday is ...
// Saturday is the schedule for Saturday.
Saturday *DaySchedule `json:"saturday,omitempty"`
// Sunday is ...
// Sunday is the schedule for Sunday.
Sunday *DaySchedule `json:"sunday,omitempty"`
// TODO: Support holidays.

// Always is ...
// Always indicates if the schedule is always active.
Always bool `json:"always,omitempty"`

// TODO: Support holidays.
}

// Target is ...
// Target represents a target object for the lending configuration.
type Target struct {
// APIVersion is ...
// APIVersion is the API version of the target object.
APIVersion string `json:"apiVersion,omitempty"`
// Kind is ...
// Kind is the kind of the target object.
Kind string `json:"kind,omitempty"`
// Name is ...
// Name is the name of the target object.
Name *string `json:"name,omitempty"`
// DefaultReplicas
// DefaultReplicas is the default number of replicas for the target object.
DefaultReplicas *int64 `json:"defaultReplicas,omitempty"`
}

// LendingConfigSpec defines the desired state of LendingConfig
// LendingConfigSpec defines the desired state of a LendingConfig.
type LendingConfigSpec struct {
// Timezone is ...
// Timezone is the timezone for the lending configuration.
Timezone string `json:"timezone,omitempty"`
// Schedules is ...
// Schedule is the schedule specification for the lending configuration.
Schedule ScheduleSpec `json:"schedule,omitempty"`
// TargetRefs is ...
// Targets is a list of target objects for the lending configuration.
Targets []Target `json:"targets,omitempty"`
}

// ObjectReference contains enough information to let you locate the
// typed referenced object inside the same namespace.
// ObjectReference contains enough information to let you locate the typed referenced object inside the same namespace.
type ObjectReference struct {
// APIVersion is ...
// APIVersion is the API version of the referenced object.
APIVersion string `json:"apiVersion,omitempty"`
// Kind is ...
// Kind is the kind of the referenced object.
Kind string `json:"kind,omitempty"`
// Name is ...
// Name is the name of the referenced object.
Name string `json:"name,omitempty"`
}

// LendingReference is ...
// LendingReference represents a reference to a lending object with the number of replicas.
type LendingReference struct {
// ObjectReference is ...
// ObjectReference is the reference to the lending object.
ObjectReference `json:"objectReference,omitempty"`
// Replicas is ...
// Replicas is the number of replicas for the lending object.
Replicas int64 `json:"replicas,omitempty"`
}

// LendingConfigStatus defines the observed state of LendingConfig
// LendingConfigStatus defines the observed state of a LendingConfig.
type LendingConfigStatus struct {
// LendingReferences is ...
// LendingReferences is a list of references to lending objects.
LendingReferences []LendingReference `json:"objectReferences,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// LendingConfig is the Schema for the lendingconfigs API
// LendingConfig is the Schema for the lendingconfigs API.
type LendingConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec LendingConfigSpec `json:"spec,omitempty"`
// Spec is the desired state of the lending configuration.
Spec LendingConfigSpec `json:"spec,omitempty"`
// Status is the observed state of the lending configuration.
Status LendingConfigStatus `json:"status,omitempty"`
}

Expand All @@ -123,7 +124,8 @@ type LendingConfig struct {
type LendingConfigList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []LendingConfig `json:"items"`
// Items is the list of LendingConfig objects.
Items []LendingConfig `json:"items"`
}

func init() {
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit a5dd74b

Please sign in to comment.