Skip to content

Commit

Permalink
Add cli API for CLIPlugin and also changes to reflect the changes don…
Browse files Browse the repository at this point in the history
…e related to k8s API dependency in tanzu-plugin-runtime module

- Add cli API for CLIPlugin (migrate apis/cli module from tanzu-framework to tanzu-cli)
- Changes to reflect the changes done related to removal of k8s API dependency in tanzu-plugin-runtime module

Signed-off-by: Prem Kumar Kalle <pkalle@vmware.com>
  • Loading branch information
prkalle committed Jan 27, 2023
1 parent 4773f39 commit 4af9ca1
Show file tree
Hide file tree
Showing 57 changed files with 878 additions and 521 deletions.
20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ GOIMPORTS := $(TOOLS_BIN_DIR)/goimports
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
VALE := $(TOOLS_BIN_DIR)/vale
MISSPELL := $(TOOLS_BIN_DIR)/misspell
TOOLING_BINARIES := $(GOIMPORTS) $(GOLANGCI_LINT) $(VALE) $(MISSPELL)
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
TOOLING_BINARIES := $(GOIMPORTS) $(GOLANGCI_LINT) $(VALE) $(MISSPELL) $(CONTROLLER_GEN)

# Build and version information

Expand Down Expand Up @@ -246,9 +247,24 @@ generate-fakes: ## Generate fakes for writing unit tests
$(MAKE) fmt

.PHONY: verify
verify: gomod fmt ## Run all verification scripts
verify: gomod fmt generate ## Run all verification scripts
./hack/check/check-dirty.sh

## --------------------------------------
## Generators
## --------------------------------------

CONTROLLER_GEN_SRC ?= "./..."

generate-controller-code: $(CONTROLLER_GEN) ## Generate code via controller-gen
$(CONTROLLER_GEN) $(GENERATOR) object:headerFile="$(ROOT_DIR)/hack/boilerplate.go.txt",year=$(shell date +%Y) paths="$(CONTROLLER_GEN_SRC)" $(OPTIONS)
$(MAKE) fmt

generate-manifests: ## Generate API manifests e.g. CRD
$(MAKE) generate-controller-code GENERATOR=crd OPTIONS="output:crd:artifacts:config=$(ROOT_DIR)/apis/config/crd/bases" CONTROLLER_GEN_SRC=$(CONTROLLER_GEN_SRC)

generate: generate-controller-code generate-manifests ## Generate controller code and manifests e.g. CRD etc.

## --------------------------------------
## Tooling Binaries
## --------------------------------------
Expand Down
71 changes: 71 additions & 0 deletions apis/cli/v1alpha1/cliplugin_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

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

configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types"
)

// ArtifactList contains an Artifact object for every supported platform of a version.
type ArtifactList []Artifact

// Artifact points to an individual plugin binary specific to a version and platform.
type Artifact struct {
// Image is a fully qualified OCI image for the plugin binary.
Image string `json:"image,omitempty"`
// AssetURI is a URI of the plugin binary. This can be a fully qualified HTTP path or a local path.
URI string `json:"uri,omitempty"`
// SHA256 hash of the plugin binary.
Digest string `json:"digest,omitempty"`
// Type of the binary artifact. Valid values are S3, GCP, OCIImage.
Type string `json:"type"`
// OS of the plugin binary in `GOOS` format.
OS string `json:"os"`
// Arch is CPU architecture of the plugin binary in `GOARCH` format.
Arch string `json:"arch"`
}

// CLIPluginSpec defines the desired state of CLIPlugin.
type CLIPluginSpec struct {
// Description is the plugin's description.
Description string `json:"description"`
// Recommended version that Tanzu CLI should use if available.
// The value should be a valid semantic version as defined in
// https://semver.org/. E.g., 2.0.1
RecommendedVersion string `json:"recommendedVersion"`
// Artifacts contains an artifact list for every supported version.
Artifacts map[string]ArtifactList `json:"artifacts"`
// Optional specifies whether the plugin is mandatory or optional
// If optional, the plugin will not get auto-downloaded as part of
// `tanzu login` or `tanzu plugin sync` command
// To view the list of plugin, user can use `tanzu plugin list` and
// to download a specific plugin run, `tanzu plugin install <plugin-name>`
Optional bool `json:"optional"`
// Target specifies the target of the plugin. Only needed for standalone plugins
Target configtypes.Target `json:"target,omitempty"`
}

//+kubebuilder:object:root=true

// CLIPlugin denotes a Tanzu cli plugin.
type CLIPlugin struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec CLIPluginSpec `json:"spec"`
}

//+kubebuilder:object:root=true

// CLIPluginList contains a list of CLIPlugin
type CLIPluginList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []CLIPlugin `json:"items"`
}

func init() {
SchemeBuilder.Register(&CLIPlugin{}, &CLIPluginList{})
}
26 changes: 26 additions & 0 deletions apis/cli/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Package v1alpha1 contains API Schema definitions for the cli v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=cli.tanzu.vmware.com
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "cli.tanzu.vmware.com", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// GroupVersionKindCLIPlugin has information about group, version and kind of CLIPlugin object.
GroupVersionKindCLIPlugin = GroupVersion.WithKind("CLIPlugin")
)
135 changes: 135 additions & 0 deletions apis/cli/v1alpha1/zz_generated.deepcopy.go

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

107 changes: 107 additions & 0 deletions apis/config/crd/bases/cli.tanzu.vmware.com_cliplugins.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: cliplugins.cli.tanzu.vmware.com
spec:
group: cli.tanzu.vmware.com
names:
kind: CLIPlugin
listKind: CLIPluginList
plural: cliplugins
singular: cliplugin
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: CLIPlugin denotes a Tanzu cli plugin.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: CLIPluginSpec defines the desired state of CLIPlugin.
properties:
artifacts:
additionalProperties:
description: ArtifactList contains an Artifact object for every
supported platform of a version.
items:
description: Artifact points to an individual plugin binary specific
to a version and platform.
properties:
arch:
description: Arch is CPU architecture of the plugin binary
in `GOARCH` format.
type: string
digest:
description: SHA256 hash of the plugin binary.
type: string
image:
description: Image is a fully qualified OCI image for the
plugin binary.
type: string
os:
description: OS of the plugin binary in `GOOS` format.
type: string
type:
description: Type of the binary artifact. Valid values are
S3, GCP, OCIImage.
type: string
uri:
description: AssetURI is a URI of the plugin binary. This
can be a fully qualified HTTP path or a local path.
type: string
required:
- arch
- os
- type
type: object
type: array
description: Artifacts contains an artifact list for every supported
version.
type: object
description:
description: Description is the plugin's description.
type: string
optional:
description: Optional specifies whether the plugin is mandatory or
optional If optional, the plugin will not get auto-downloaded as
part of `tanzu login` or `tanzu plugin sync` command To view the
list of plugin, user can use `tanzu plugin list` and to download
a specific plugin run, `tanzu plugin install <plugin-name>`
type: boolean
recommendedVersion:
description: Recommended version that Tanzu CLI should use if available.
The value should be a valid semantic version as defined in https://semver.org/.
E.g., 2.0.1
type: string
target:
description: Target specifies the target of the plugin. Only needed
for standalone plugins
type: string
required:
- artifacts
- description
- optional
- recommendedVersion
type: object
required:
- metadata
- spec
type: object
served: true
storage: true
5 changes: 3 additions & 2 deletions cmd/plugin/builder/command/publish/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

apimachineryjson "k8s.io/apimachinery/pkg/runtime/serializer/json"

"github.com/vmware-tanzu/tanzu-framework/apis/cli/v1alpha1"
configtypes "github.com/vmware-tanzu/tanzu-plugin-runtime/config/types"
rtplugin "github.com/vmware-tanzu/tanzu-plugin-runtime/plugin"

"github.com/vmware-tanzu/tanzu-cli/apis/cli/v1alpha1"
"github.com/vmware-tanzu/tanzu-cli/pkg/common"
)

Expand Down Expand Up @@ -123,7 +124,7 @@ func newCLIPluginResource(plugin, target, description, version string, artifacts
cliPlugin.Spec.Description = description
cliPlugin.Spec.RecommendedVersion = version
cliPlugin.Spec.Artifacts = artifacts
cliPlugin.Spec.Target = v1alpha1.Target(target)
cliPlugin.Spec.Target = configtypes.Target(target)
return cliPlugin
}

Expand Down
Loading

0 comments on commit 4af9ca1

Please sign in to comment.