Skip to content

Commit 69e3d16

Browse files
committed
feat: added cli with init and uninstall command; also added custom resource for usage calculation
1 parent d057db4 commit 69e3d16

26 files changed

+998
-1361
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "hack/common"]
2+
path = hack/common
3+
url = https://github.com/openmcp-project/build

.golangci.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: "2"
2+
run:
3+
allow-parallel-runners: true
4+
linters:
5+
default: none
6+
enable:
7+
- copyloopvar
8+
- dupl
9+
- errcheck
10+
- ginkgolinter
11+
- goconst
12+
- gocyclo
13+
- govet
14+
- ineffassign
15+
- misspell
16+
- nakedret
17+
- prealloc
18+
- revive
19+
- staticcheck
20+
- unconvert
21+
- unparam
22+
- unused
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
29+
rules:
30+
- linters:
31+
- dupl
32+
path: internal/*
33+
paths:
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
formatters:
38+
enable:
39+
- gofmt
40+
- goimports
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- third_party$
45+
- builtin$
46+
- examples$

Makefile

Lines changed: 0 additions & 232 deletions
This file was deleted.

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hack/common/Makefile

Taskfile.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 3
2+
3+
includes:
4+
shared:
5+
taskfile: hack/common/Taskfile_controller.yaml
6+
flatten: true
7+
excludes: [] # put task names in here which are overwritten in this file
8+
vars:
9+
NESTED_MODULES: ""
10+
API_DIRS: "{{.ROOT_DIR}}/api/..."
11+
MANIFEST_OUT: "{{.ROOT_DIR}}/api/crds/manifests"
12+
CODE_DIRS: "{{.ROOT_DIR}}/cmd/... {{.ROOT_DIR}}/internal/... {{.ROOT_DIR}}/api/..."
13+
COMPONENTS: "usage-operator"
14+
REPO_URL: "https://github.com/openmcp-project/usage-operator"
15+
GENERATE_DOCS_INDEX: "true"
16+
CHART_COMPONENTS: "[]"

VERSION

Whitespace-only changes.

api/crds/crds.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package crds
2+
3+
import (
4+
"embed"
5+
6+
crdutil "github.com/openmcp-project/controller-utils/pkg/crds"
7+
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
8+
)
9+
10+
//go:embed manifests
11+
var CRDFS embed.FS
12+
13+
func CRDs() ([]*apiextv1.CustomResourceDefinition, error) {
14+
return crdutil.CRDsFromFileSystem(CRDFS, "manifests")
15+
}

config/crd/bases/usage.openmcp.cloud_mcpdailies.yaml renamed to api/crds/manifests/usage.openmcp.cloud_mcpdailies.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.18.0
7+
labels:
8+
openmcp.cloud/cluster: onboarding
79
name: mcpdailies.usage.openmcp.cloud
810
spec:
911
group: usage.openmcp.cloud
@@ -50,14 +52,14 @@ spec:
5052
daily_usage:
5153
items:
5254
properties:
53-
hours:
54-
type: integer
55-
timestamp:
55+
date:
5656
format: date-time
5757
type: string
58+
hours:
59+
type: string
5860
required:
61+
- date
5962
- hours
60-
- timestamp
6163
type: object
6264
type: array
6365
mcp:

api/usage/v1/mcpdaily_types.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package v1
1818

1919
import (
20+
"fmt"
21+
"time"
22+
2023
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2124
)
2225

@@ -38,13 +41,28 @@ type MCPDailyStatus struct {
3841
}
3942

4043
type DailyUsage struct {
41-
Timestamp metav1.Time `json:"timestamp"`
42-
Hours int `json:"hours"`
44+
Date metav1.Time `json:"date"`
45+
Usage metav1.Duration `json:"hours"`
46+
}
47+
48+
func NewDailyUsage(date time.Time, hours int) (DailyUsage, error) {
49+
duration, err := time.ParseDuration(fmt.Sprintf("%vh", hours))
50+
if err != nil {
51+
return DailyUsage{}, err
52+
}
53+
54+
return DailyUsage{
55+
Date: metav1.NewTime(date),
56+
Usage: metav1.Duration{
57+
Duration: duration,
58+
},
59+
}, nil
4360
}
4461

4562
// +kubebuilder:object:root=true
4663
// +kubebuilder:subresource:status
4764
// +kubebuilder:resource:scope=Cluster
65+
// +kubebuilder:metadata:labels="openmcp.cloud/cluster=onboarding"
4866

4967
// MCPDaily is the Schema for the mcpdailies API.
5068
type MCPDaily struct {

0 commit comments

Comments
 (0)