Skip to content

Commit

Permalink
add back deleted deepcopy files (#362)
Browse files Browse the repository at this point in the history
* add back deleted deepcopy files

* added missing deepcopy tags

* added missing deepcopy tags

* use metav1 time instead of time.Time

* added github check for generation
  • Loading branch information
Skarlso authored May 10, 2023
1 parent 9baa958 commit 8c3f49d
Show file tree
Hide file tree
Showing 7 changed files with 768 additions and 9 deletions.
38 changes: 36 additions & 2 deletions .github/workflows/lint_and_test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: lint-and-test

on:
on:
pull_request_target:
push:
branches:
Expand Down Expand Up @@ -69,4 +69,38 @@ jobs:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.49.0
- name: Lint
run: |
PATH=$PATH:$(go env GOPATH)/bin make check
PATH=$PATH:$(go env GOPATH)/bin make check
generate:
name: Generate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Cache go-build and mod
uses: actions/cache@v3
with:
path: |
~/.cache/go-build/
~/go/pkg/mod/
key: go-${{ hashFiles('go.sum') }}
restore-keys: |
go-
- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Generate
run: |
PATH=$PATH:$(go env GOPATH)/bin make generate
- name: Check for diff
run: |
git diff --exit-code --shortstat
- name: Generate DeepCopy
run: |
PATH=$PATH:$(go env GOPATH)/bin make generate-deepcopy
- name: Check for diff
run: |
git diff --exit-code --shortstat
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ EFFECTIVE_VERSION := $(VERSION)+$(shell git rev-par
GIT_TREE_STATE := $(shell [ -z "$$(git status --porcelain 2>/dev/null)" ] && echo clean || echo dirty)
COMMIT := $(shell git rev-parse --verify HEAD)

CONTROLLER_TOOLS_VERSION ?= v0.9.0
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen

CREDS ?=
OCM := go run $(REPO_ROOT)/cmds/ocm $(CREDS)
CTF_TYPE ?= tgz
Expand Down Expand Up @@ -65,6 +68,15 @@ test:
generate:
@$(REPO_ROOT)/hack/generate.sh $(REPO_ROOT)/pkg... $(REPO_ROOT)/cmds/ocm/... $(REPO_ROOT)/cmds/helminst/...

.PHONY: generate-deepcopy
generate-deepcopy: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths=./pkg/contexts/ocm/compdesc/versions/... paths=./pkg/contexts/ocm/compdesc/meta/...

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

.PHONY: verify
verify: check

Expand Down
12 changes: 12 additions & 0 deletions pkg/contexts/ocm/compdesc/meta/v1/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func NewExcludeFromSignatureDigest() *DigestSpec {

////////////////////////////////////////////////////////////////////////////////

// NestedDigests defines a list of nested components.
// +k8s:deepcopy-gen=true
// +k8s:openapi-gen=true
type NestedDigests []NestedComponentDigests

func (d NestedDigests) String() string {
Expand Down Expand Up @@ -149,6 +152,9 @@ func (d NestedDigests) Lookup(name, version string) *NestedComponentDigests {
return nil
}

// NestedComponentDigests defines nested components.
// +k8s:deepcopy-gen=true
// +k8s:openapi-gen=true
type NestedComponentDigests struct {
Name string `json:"name"`
Version string `json:"version"`
Expand Down Expand Up @@ -186,6 +192,9 @@ func (d *NestedComponentDigests) Copy() *NestedComponentDigests {
return &r
}

// ArtefactDigests defines a list of artefact digest information.
// +k8s:deepcopy-gen=true
// +k8s:openapi-gen=true
type ArtefactDigests []ArtefactDigest

func (d ArtefactDigests) Lookup(name, version string, extra Identity) *ArtefactDigest {
Expand All @@ -210,6 +219,9 @@ func (d ArtefactDigests) Match(o ArtefactDigests) bool {
return true
}

// ArtefactDigest defines artefact digest information.
// +k8s:deepcopy-gen=true
// +k8s:openapi-gen=true
type ArtefactDigest struct {
Name string `json:"name"`
Version string `json:"version"`
Expand Down
22 changes: 15 additions & 7 deletions pkg/contexts/ocm/compdesc/meta/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package v1
import (
"time"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/open-component-model/ocm/pkg/errors"
Expand Down Expand Up @@ -161,23 +162,30 @@ func (o *Provider) Copy() *Provider {

////////////////////////////////////////////////////////////////////////////////

type _time = time.Time
type _time = v1.Time

// Timestamp is time rounded to seconds.
// +k8s:deepcopy-gen=true
type Timestamp struct {
_time
_time `json:",inline"`
}

func NewTimestamp() Timestamp {
return Timestamp{time.Now().Round(time.Second)}
return Timestamp{
_time: v1.NewTime(time.Now().Round(time.Second)),
}
}

func NewTimestampP() *Timestamp {
return &Timestamp{time.Now().Round(time.Second)}
return &Timestamp{
_time: v1.NewTime(time.Now().Round(time.Second)),
}
}

func NewTimestampFor(t time.Time) Timestamp {
return Timestamp{t.Round(time.Second)}
return Timestamp{
_time: v1.NewTime(t.Round(time.Second)),
}
}

// MarshalJSON implements the json.Marshaler interface.
Expand Down Expand Up @@ -210,11 +218,11 @@ func (t *Timestamp) UnmarshalJSON(data []byte) error {
}

func (t *Timestamp) Time() time.Time {
return t._time
return t._time.Time
}

func (t *Timestamp) Equal(o Timestamp) bool {
return t._time.Equal(o._time)
return t._time.Equal(&o._time)
}

func (t *Timestamp) UTC() Timestamp {
Expand Down
Loading

0 comments on commit 8c3f49d

Please sign in to comment.