Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

[Draft] Adding 'pluginRuntimeVersion' to tanzu <plugin> info command output #3793

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/dev_tag_retrieval_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ jobs:
echo ::set-output name=NEXT_VERSION::$major.$minor.$patch-dev

- name: Update version in file
run: sed -i -e "/TKGManagementClusterPluginVersion/ s/= .*/= \"${{ steps.next_version.outputs.NEXT_VERSION }}\"/" tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go
run: |
sed -i -e "/TKGManagementClusterPluginVersion/ s/= .*/= \"${{ steps.next_version.outputs.NEXT_VERSION }}\"/" tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go
sed -i -e "/Version/ s/= .*/= \"${{ steps.next_version.outputs.NEXT_VERSION }}\"/" cli/runtime/version/zz_generated_plugin_runtime_version.go

- name: Set variables
id: vars
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,16 @@ generate-telemetry-bindata: $(GOBINDATA) ## Generate telemetry bindata
generate-bindata: generate-telemetry-bindata generate-ui-bindata

.PHONY: configure-bom
configure-bom: ## Configure bill of materials
configure-bom: configure-plugin-runtime-version ## Configure bill of materials
# Update default BoM Filename variable in tkgconfig pkg
sed "s+TKG_DEFAULT_IMAGE_REPOSITORY+${TKG_DEFAULT_IMAGE_REPOSITORY}+g" hack/update-bundled-bom-filename/update-bundled-default-bom-files-configdata.txt | \
sed "s+TKG_DEFAULT_COMPATIBILITY_IMAGE_PATH+${TKG_DEFAULT_COMPATIBILITY_IMAGE_PATH}+g" | \
sed "s+TKG_MANAGEMENT_CLUSTER_PLUGIN_VERSION+${BUILD_VERSION}+g" > tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go

.PHONY: configure-plugin-runtime-version
configure-plugin-runtime-version: ## Configure plugin runtime version
$(MAKE) configure-version -C cli/runtime

.PHONY: generate-ui-swagger-api
generate-ui-swagger-api: ## Generate swagger files for UI backend
rm -rf ${UI_DIR}/server/client ${UI_DIR}/server/models ${UI_DIR}/server/restapi/operations
Expand Down
20 changes: 20 additions & 0 deletions cli/runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ GOBIN=$(shell go env GOBIN)
endif
GO := go

NUL = /dev/null
ifeq ($(GOHOSTOS),windows)
NUL = NUL
endif

BUILD_SHA ?= $$(git describe --match=$(git rev-parse --short HEAD) --always --dirty)
BUILD_DATE ?= $$(date -u +"%Y-%m-%d")
BUILD_VERSION ?= $(shell git describe --tags --abbrev=0 2>$(NUL))

ifeq ($(strip $(BUILD_VERSION)),)
BUILD_VERSION = dev
endif


# Directories
TOOLS_DIR := $(abspath $(MODULE_ROOT_DIR)/hack/tools)
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
Expand All @@ -40,6 +54,12 @@ help: ## Display this help (default)
.PHONY: all
all: test ## Tests the library


.PHONY: configure-version
configure-version: ## Configure plugin runtime version
# Update plugin runtime version variable in version pkg
sed "s+TANZU_PLUGIN_RUNTIME_VERSION+${BUILD_VERSION}+g" hack/update-bundled-plugin-runtime-version/update-bundled-plugin-runtime-version.txt > version/zz_generated_plugin_runtime_version.go

## --------------------------------------
## Testing
## --------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package version

// IMPORTANT: Please !!DO NOT!!! change the content of this file manually
// This file is auto-generated based on the version details provided during build time
// and the values mentioned here are used to store the library version

// All the variables are set during build time
// Note: Please !!DO NOT!!! change the name or remove this variable
var (
Version string = "TANZU_PLUGIN_RUNTIME_VERSION"
)
18 changes: 17 additions & 1 deletion cli/runtime/plugin/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ import (
"github.com/spf13/cobra"

cliapi "github.com/vmware-tanzu/tanzu-framework/cli/runtime/apis/cli/v1alpha1"
rtversion "github.com/vmware-tanzu/tanzu-framework/cli/runtime/version"
)

// pluginInfo describes a plugin information. This is a super set of PluginDescriptor
// It includes some additional metadata that plugin runtime configures
type pluginInfo struct {
// PluginDescriptor describes a plugin binary.
cliapi.PluginDescriptor `json:",inline" yaml:",inline"`

// PluginRuntimeVersion of the plugin. Must be a valid semantic version https://semver.org/
// This version specifies the version of Plugin Runtime that was used to build the plugin
PluginRuntimeVersion string `json:"pluginRuntimeVersion" yaml:"pluginRuntimeVersion"`
}

func newInfoCmd(desc *cliapi.PluginDescriptor) *cobra.Command {
cmd := &cobra.Command{
Use: "info",
Short: "Plugin info",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
b, err := json.Marshal(desc)
pi := pluginInfo{
PluginDescriptor: *desc,
PluginRuntimeVersion: rtversion.Version,
}
b, err := json.Marshal(pi)
if err != nil {
return err
}
Expand Down
24 changes: 18 additions & 6 deletions cli/runtime/plugin/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package plugin

import (
"encoding/json"
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -43,16 +42,29 @@ func TestInfo(t *testing.T) {
DocURL: "https://docs.example.com",
Hidden: false,
}
expected, err := json.Marshal(descriptor)
if err != nil {
t.Error(err)
}

infoCmd := newInfoCmd(&descriptor)
err = infoCmd.Execute()
w.Close()
assert.Nil(err)

got := <-c
assert.Equal(fmt.Sprintf("%s\n", expected), string(got))

expectedInfo := pluginInfo{
PluginDescriptor: descriptor,
}

gotInfo := &pluginInfo{}
err = json.Unmarshal(got, gotInfo)
if err != nil {
t.Error(err)
}

assert.Equal(expectedInfo.Name, gotInfo.Name)
assert.Equal(expectedInfo.Description, gotInfo.Description)
assert.Equal(expectedInfo.Version, gotInfo.Version)
assert.Equal(expectedInfo.BuildSHA, gotInfo.BuildSHA)
assert.Equal(expectedInfo.DocURL, gotInfo.DocURL)
assert.Equal(expectedInfo.Hidden, gotInfo.Hidden)
assert.NotEmpty(gotInfo.PluginRuntimeVersion)
}
14 changes: 14 additions & 0 deletions cli/runtime/version/zz_generated_plugin_runtime_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package version

// IMPORTANT: Please !!DO NOT!!! change the content of this file manually
// This file is auto-generated based on the version details provided during build time
// and the values mentioned here are used to store the library version

// All the variables are set during build time
// Note: Please !!DO NOT!!! change the name or remove this variable
var (
Version string = "v0.28.0-dev"
)
15 changes: 8 additions & 7 deletions hack/verify-dirty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ echo "Verify uncommitted files..."
echo "#############################"

# Option to ignore changes to compatibility image path in
# tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go. This is to support `usebom` directive
# tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go and plugin runtime version in
# cli/runtime/version/zz_generated_plugin_runtime_version.go. This is to support `usebom` directive
# in tests.
ignore_file=':!tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go'
ignore_files=(':(exclude)tkg/tkgconfigpaths/zz_bundled_default_bom_files_configdata.go' ':(exclude)cli/runtime/version/zz_generated_plugin_runtime_version.go')
# Temporarily excluding UI generated bindata file from verify (zz_generated.bindata.go). Currently running into issues
# blocking the CI main build. CI generated bindata is different from bindata file generated on local
# developer machines, causing this failure. Need to root cause and then remove this exclusion.
ignore_file_ui_bindata=':!tkg/manifest/server/zz_generated.bindata.go'

if ! (git diff --quiet HEAD -- . "${ignore_file}" "${ignore_file_ui_bindata}"); then
if ! (git diff --quiet HEAD -- . "${ignore_files[@]}" "${ignore_file_ui_bindata}"); then
echo -e "\nThe following files are uncommitted. Please commit them or add them to .gitignore:";
git diff --name-only HEAD -- . "${ignore_file}" "${ignore_file_ui_bindata}" | awk '{print "- " $0}'
git diff --name-only HEAD -- . "${ignore_files[@]}" "${ignore_file_ui_bindata}" | awk '{print "- " $0}'
echo -e "\nDiff:"
git --no-pager diff HEAD -- . "${ignore_file}" "${ignore_file_ui_bindata}"
git --no-pager diff HEAD -- . "${ignore_files[@]}" "${ignore_file_ui_bindata}"
exit 1
else
echo "OK"
Expand All @@ -33,7 +34,7 @@ echo "#############################"
echo "Verify make package-vendir-sync..."
echo "#############################"
make package-vendir-sync
if ! (git diff --quiet HEAD -- . "${ignore_file}" "${ignore_file_ui_bindata}"); then
if ! (git diff --quiet HEAD -- . "${ignore_files[@]}" "${ignore_file_ui_bindata}"); then
echo "FAIL"
echo "'make package-vendir-sync' generated diffs!"
echo "Please verify if package CRD changes are intended and commit the diffs if so."
Expand All @@ -48,7 +49,7 @@ echo "#############################"
echo "Verify make configure-bom..."
echo "#############################"
make configure-bom
if ! (git diff --quiet HEAD -- . "${ignore_file}" "${ignore_file_ui_bindata}"); then
if ! (git diff --quiet HEAD -- . "${ignore_files[@]}" "${ignore_file_ui_bindata}"); then
echo "FAIL"
echo "'make configure-bom' generated diffs!"
echo "Please verify if default BOM variable changes are intended and commit the diffs if so."
Expand Down