Skip to content

Commit

Permalink
chore: Move Inventory object to pkg/apis/actuation
Browse files Browse the repository at this point in the history
- Replace custom TypeMeta & ObjectMeta with standard metav1 structs
  to allow Inventory to satisfy the metav1.Object, runtime.Object,
  and client.Object interfaces. This should make the Inventory API
  easier to use and easily convertable to an Unstructured object.

BREAKING CHANGE: Move inventory.Inventory to actuation.Inventory (under pkg/apis/)
  • Loading branch information
karlkfi committed Feb 15, 2022
1 parent 2b7c073 commit bb84f24
Show file tree
Hide file tree
Showing 12 changed files with 357 additions and 214 deletions.
2 changes: 2 additions & 0 deletions LICENSE_TEMPLATE_GO
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright YEAR The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ install-addlicense:
install-lint:
(which $(GOPATH)/bin/golangci-lint || go install github.com/golangci/golangci-lint/cmd/[email protected])

generate: install-stringer
install-deepcopy-gen:
(which $(GOPATH)/bin/deepcopy-gen || go install k8s.io/code-generator/cmd/[email protected])

generate-deepcopy: install-deepcopy-gen
hack/run-in-gopath.sh deepcopy-gen --input-dirs ./pkg/apis/... -O zz_generated.deepcopy --go-header-file ./LICENSE_TEMPLATE_GO

generate: install-stringer generate-deepcopy
go generate ./...

license: install-addlicense
Expand Down
43 changes: 43 additions & 0 deletions hack/run-in-gopath.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
# Copyright 2021 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0

set -o errexit -o nounset -o pipefail -o posix

PKG_PATH="sigs.k8s.io/cli-utils"

REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"

# Make a new temporary GOPATH directory
export GOPATH=$(mktemp -d -t cli-utils-gopath.XXXXXXXXXX)
# Clean up on exit (modcache has read-only files, so clean that first)
trap "go clean -modcache && rm '${GOPATH}/src/${PKG_PATH}' && rm -rf '${GOPATH}'" EXIT

# Make sure we can read, write, and delete
chmod a+rw "${GOPATH}"

# Use a temporary cache
export GOCACHE="${GOPATH}/cache"

# Create a symlink for the local repo in the GOPATH
mkdir -p "${GOPATH}/src/${PKG_PATH}"
rm -r "${GOPATH}/src/${PKG_PATH}"
ln -s "${REPO_ROOT}" "${GOPATH}/src/${PKG_PATH}"

# Make sure our own Go binaries are in PATH.
export PATH="${GOPATH}/bin:${PATH}"

# Set GOROOT so binaries that parse code can work properly.
export GOROOT=$(go env GOROOT)

# Unset GOBIN in case it already exists in the current session.
unset GOBIN

# enter the GOPATH before executing the command
cd "${GOPATH}/src/${PKG_PATH}"

# Run the user-provided command.
"${@}"

# exit the GOPATH before deleting it
cd "${REPO_ROOT}"

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

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

8 changes: 8 additions & 0 deletions pkg/apis/actuation/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

// Package actuation contains API Schema definitions for the
// cli-utils.kubernetes.io API group.
// +k8s:deepcopy-gen=package
// +groupName=cli-utils.kubernetes.io
package actuation // import "sigs.k8s.io/cli-utils/pkg/apis/actuation"

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

39 changes: 7 additions & 32 deletions pkg/inventory/types.go → pkg/apis/actuation/types.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package inventory
package actuation

import "k8s.io/apimachinery/pkg/types"
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

// Inventory represents the inventory object in memory.
// Inventory is currently only used for in-memory storage and not serialized to
// disk or to the API server.
// TODO: Replace InventoryInfo with Inventory.TypeMeta & Inventory.ObjectMeta
// TODO: Replace object.ObjMetadataSet in Storage interface with Inventory.Spec
type Inventory struct {
TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec InventorySpec `json:"spec,omitempty"`
Status InventoryStatus `json:"status,omitempty"`
Expand Down Expand Up @@ -106,29 +107,3 @@ const (
ReconcileFailed // Failed
ReconcileTimeout // Timeout
)

// TypeMeta describes a REST resource.
type TypeMeta struct {
// Kind is a string value representing the REST resource this object represents.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
Kind string `json:"kind,omitempty"`

// APIVersion defines the versioned schema of this representation of an object.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
APIVersion string `json:"apiVersion,omitempty"`
}

// ObjectMeta describes an individual object instance of a REST resource.
// TODO: Do we need other fields, like UID, Generation, ResourceVersion, and CreationTimestamp?
type ObjectMeta struct {
// Name identifies an object instance of a REST resource.
// More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"`

// Namespace identifies a group of objects across REST resources.
// If namespace is specified, the resource must be namespace-scoped.
// If namespace is omitted, the resource must be cluster-scoped.
// More info: http://kubernetes.io/docs/user-guide/namespaces
// +optional
Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"`
}
104 changes: 104 additions & 0 deletions pkg/apis/actuation/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 bb84f24

Please sign in to comment.