diff --git a/package.json b/package.json index cf32b062..7d11a49c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "venona", - "version": "1.0.2", + "version": "1.0.3", "description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline", "main": "index.js", "scripts": { diff --git a/venonactl/VERSION b/venonactl/VERSION index 6d7de6e6..21e8796a 100644 --- a/venonactl/VERSION +++ b/venonactl/VERSION @@ -1 +1 @@ -1.0.2 +1.0.3 diff --git a/venonactl/cmd/cmdutils.go b/venonactl/cmd/cmdutils.go index 17c441d5..16519b19 100644 --- a/venonactl/cmd/cmdutils.go +++ b/venonactl/cmd/cmdutils.go @@ -29,9 +29,6 @@ var ( version = "dev" commit = "none" date = "unknown" - // set to false by default, when running hack/build.sh will change to true - // to prevent version checking during development - localDevFlow = "false" verbose bool @@ -41,8 +38,6 @@ var ( cfContext string kubeConfigPath string - - skipVerionCheck bool ) func buildBasicStore(logger logger.Logger) { @@ -64,30 +59,7 @@ func buildBasicStore(logger logger.Logger) { s.ServerCert = &certs.ServerCert{} s.AppName = store.ApplicationName - - if skipVerionCheck || localDevFlow == "true" { - latestVersion := &store.LatestVersion{ - Version: store.DefaultVersion, - IsDefault: true, - } - s.Version.Latest = latestVersion - logger.Debug("Skipping version check") - } else { - latestVersion := &store.LatestVersion{ - Version: store.GetLatestVersion(logger), - IsDefault: false, - } - s.Image.Tag = latestVersion.Version - s.Version.Latest = latestVersion - res, _ := store.IsRunningLatestVersion() - // the local version and the latest version not match - // make sure the command is no venonactl version - if !res { - logger.Info("New version is avaliable, please update", - "Local-Version", s.Version.Current.Version, - "Latest-Version", s.Version.Latest.Version) - } - } + s.Image.Tag = s.Version.Current.Version } func extendStoreWithCodefershClient(logger logger.Logger) error { diff --git a/venonactl/cmd/install-agent.go b/venonactl/cmd/install-agent.go index 0a311a28..c51f7cea 100644 --- a/venonactl/cmd/install-agent.go +++ b/venonactl/cmd/install-agent.go @@ -19,32 +19,32 @@ limitations under the License. import ( "fmt" - "github.com/codefresh-io/venona/venonactl/pkg/store" - "github.com/codefresh-io/venona/venonactl/pkg/plugins" "github.com/codefresh-io/venona/venonactl/pkg/logger" + "github.com/codefresh-io/venona/venonactl/pkg/plugins" + "github.com/codefresh-io/venona/venonactl/pkg/store" "github.com/spf13/cobra" "github.com/spf13/viper" ) var installAgentCmdOptions struct { - dryRun bool - kube struct { + dryRun bool + kube struct { namespace string inCluster bool context string nodeSelector string } - venona struct { + venona struct { version string } - agentToken string - agentID string - kubernetesRunnerType bool - tolerations string + agentToken string + agentID string + kubernetesRunnerType bool + tolerations string } var installAgentCmd = &cobra.Command{ - Use: "agent", + Use: "agent", Short: "Install Codefresh's agent ", Run: func(cmd *cobra.Command, args []string) { s := store.GetStore() @@ -59,7 +59,7 @@ var installAgentCmd = &cobra.Command{ cfAPIHost = "https://g.codefresh.io" } builderInstallOpt := &plugins.InstallOptions{ - CodefreshHost: cfAPIHost, + CodefreshHost: cfAPIHost, } if installAgentCmdOptions.agentToken == "" { @@ -93,10 +93,8 @@ var installAgentCmd = &cobra.Command{ version := installAgentCmdOptions.venona.version lgr.Info("Version set manually", "version", version) s.Image.Tag = version - s.Version.Latest.Version = version } - kns, err := parseNodeSelector(installAgentCmdOptions.kube.nodeSelector) if err != nil { dieOnError(err) @@ -107,7 +105,6 @@ var installAgentCmd = &cobra.Command{ builderInstallOpt.KubeBuilder = getKubeClientBuilder(builderInstallOpt.ClusterName, s.KubernetesAPI.Namespace, s.KubernetesAPI.ConfigPath, s.KubernetesAPI.InCluster) builderInstallOpt.ClusterNamespace = s.KubernetesAPI.Namespace - builder.Add(plugins.VenonaPluginType) values := s.BuildValues() @@ -120,10 +117,9 @@ var installAgentCmd = &cobra.Command{ lgr.Info("Agent installation completed Successfully") }, - } -func init() { +func init() { installCommand.AddCommand(installAgentCmd) viper.BindEnv("kube-namespace", "KUBE_NAMESPACE") @@ -141,12 +137,10 @@ func init() { installAgentCmd.Flags().BoolVar(&installAgentCmdOptions.kubernetesRunnerType, "kubernetes-runner-type", false, "Set the runner type to kubernetes (alpha feature)") } - - -func fillCodefreshAPI(logger logger.Logger) { +func fillCodefreshAPI(logger logger.Logger) { s := store.GetStore() s.CodefreshAPI = &store.CodefreshAPI{ - Host: cfAPIHost, + Host: cfAPIHost, } - -} \ No newline at end of file + +} diff --git a/venonactl/cmd/root.go b/venonactl/cmd/root.go index 8f872f0f..e691b67c 100644 --- a/venonactl/cmd/root.go +++ b/venonactl/cmd/root.go @@ -49,6 +49,5 @@ func init() { rootCmd.PersistentFlags().StringVar(&kubeConfigPath, "kube-config-path", viper.GetString("kubeconfig"), "Path to kubeconfig file (default is $HOME/.kube/config) [$KUBECONFIG]") rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Print logs") - rootCmd.PersistentFlags().BoolVar(&skipVerionCheck, "skip-version-check", false, "Do not compare current Venona's version with latest") } diff --git a/venonactl/cmd/version.go b/venonactl/cmd/version.go index 7a5c0291..c3c04abf 100644 --- a/venonactl/cmd/version.go +++ b/venonactl/cmd/version.go @@ -34,7 +34,6 @@ var versionCmd = &cobra.Command{ fmt.Printf("Date: %s\n", s.Version.Current.Date) fmt.Printf("Commit: %s\n", s.Version.Current.Commit) fmt.Printf("Local Version: %s\n", s.Version.Current.Version) - fmt.Printf("Latest version: %s\n", s.Version.Latest.Version) }, } diff --git a/venonactl/hack/build.sh b/venonactl/hack/build.sh index 613c92da..9f404dff 100755 --- a/venonactl/hack/build.sh +++ b/venonactl/hack/build.sh @@ -4,6 +4,8 @@ OUTFILE=/usr/local/bin/venonactl go generate ${PWD}/hack/generate.go go fmt ${PWD}/pkg/obj/kubeobj/kubeobj.go go fmt ${PWD}/pkg/templates/kubernetes/templates.go -go build -ldflags '-X github.com/codefresh-io/venona/venonactl/cmd.localDevFlow=true' -o $OUTFILE main.go +VERSION="$(cat VERSION)-$(git rev-parse --short HEAD)" +echo "Setting up version $VERSION" +go build -ldflags "-X github.com/codefresh-io/venona/venonactl/cmd.version=$VERSION" -o $OUTFILE main.go chmod +x $OUTFILE diff --git a/venonactl/pkg/store/store.go b/venonactl/pkg/store/store.go index b501cc83..44bef63f 100644 --- a/venonactl/pkg/store/store.go +++ b/venonactl/pkg/store/store.go @@ -28,7 +28,7 @@ type ( KubernetesAPI *KubernetesAPI - AgentAPI *AgentAPI + AgentAPI *AgentAPI ClusterInCodefresh string @@ -56,8 +56,8 @@ type ( } AgentAPI struct { - Token string - Id string + Token string + Id string } Image struct { @@ -67,7 +67,6 @@ type ( Version struct { Current *CurrentVersion - Latest *LatestVersion } CurrentVersion struct { @@ -75,12 +74,6 @@ type ( Commit string Date string } - LatestVersion struct { - Version string - Commit string - Date string - IsDefault bool - } ) func GetStore() *Values { @@ -94,12 +87,12 @@ func GetStore() *Values { func (s *Values) BuildValues() map[string]interface{} { return map[string]interface{}{ "AppName": ApplicationName, - "Version": s.Version.Latest.Version, + "Version": s.Version.Current.Version, "CodefreshHost": s.CodefreshAPI.Host, "Mode": ModeInCluster, "Image": map[string]string{ "Name": "codefresh/venona", - "Tag": s.Version.Latest.Version, + "Tag": s.Version.Current.Version, }, "VolumeProvisionerImage": map[string]string{ "Name": "codefresh/dind-volume-provisioner", @@ -107,9 +100,9 @@ func (s *Values) BuildValues() map[string]interface{} { }, "Namespace": s.KubernetesAPI.Namespace, "ConfigPath": s.KubernetesAPI.ConfigPath, - "Context": s.KubernetesAPI.ContextName, + "Context": s.KubernetesAPI.ContextName, "NodeSelector": s.KubernetesAPI.NodeSelector, - "Tolerations": s.KubernetesAPI.Tolerations, + "Tolerations": s.KubernetesAPI.Tolerations, "AgentToken": s.AgentAPI.Token, "AgentId": s.AgentAPI.Id, "ServerCert": map[string]string{ diff --git a/venonactl/pkg/store/utils.go b/venonactl/pkg/store/utils.go deleted file mode 100644 index af8c572d..00000000 --- a/venonactl/pkg/store/utils.go +++ /dev/null @@ -1,52 +0,0 @@ -package store - -import ( - "context" - "strings" - - "github.com/google/go-github/v21/github" - version "github.com/hashicorp/go-version" -) - -const ( - DefaultVersion = "latest" -) - -type ( - logger interface { - Debug(string, ...interface{}) - } -) - -func GetLatestVersion(logger logger) string { - version := DefaultVersion - client := github.NewClient(nil) - releases, _, err := client.Repositories.ListReleases(context.Background(), "codefresh-io", "venona", &github.ListOptions{}) - if err != nil { - logger.Debug("Request to get latest version of venona been rejected , setting version to latest. Original error: %s", err.Error()) - return version - } - for _, release := range releases { - name := strings.Split(*release.Name, "v") - if len(name) == 2 { - return name[1] - } - } - return version -} - -func IsRunningLatestVersion() (bool, error) { - s := GetStore() - current, err := version.NewVersion(s.Version.Current.Version) - if err != nil { - return false, err - } - latest, err := version.NewVersion(s.Version.Latest.Version) - if err != nil { - return false, err - } - if current.LessThan(latest) { - return false, nil - } - return true, nil -}