-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add k8s plugin's toolregistry implementation (#5243)
* Pass install script from arg Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> * Add k8s plugin's toolregistry Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> --------- Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
- Loading branch information
Showing
3 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
pkg/app/pipedv1/plugin/kubernetes/toolregistry/registry.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package toolregistry installs and manages the needed tools | ||
// such as kubectl, helm... for executing tasks in pipeline. | ||
package toolregistry | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/toolregistry" | ||
) | ||
|
||
// Registry provides functions to get path to the needed tools. | ||
type Registry interface { | ||
Kubectl(ctx context.Context, version string) (string, error) | ||
Kustomize(ctx context.Context, version string) (string, error) | ||
Helm(ctx context.Context, version string) (string, error) | ||
} | ||
|
||
func NewRegistry(client toolregistry.ToolRegistry) Registry { | ||
return ®istry{ | ||
client: client, | ||
} | ||
} | ||
|
||
type registry struct { | ||
client toolregistry.ToolRegistry | ||
} | ||
|
||
func (r *registry) Kubectl(ctx context.Context, version string) (string, error) { | ||
return r.client.InstallTool(ctx, "kubectl", version, kubectlInstallScript) | ||
} | ||
|
||
func (r *registry) Kustomize(ctx context.Context, version string) (string, error) { | ||
return r.client.InstallTool(ctx, "kustomize", version, kustomizeInstallScript) | ||
} | ||
|
||
func (r *registry) Helm(ctx context.Context, version string) (string, error) { | ||
return r.client.InstallTool(ctx, "helm", version, helmInstallScript) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 The PipeCD Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package toolregistry | ||
|
||
const kubectlInstallScript = ` | ||
cd {{ .TmpDir }} | ||
curl -LO https://storage.googleapis.com/kubernetes-release/release/v{{ .Version }}/bin/{{ .Os }}/{{ .Arch }}/kubectl | ||
mv kubectl {{ .OutPath }} | ||
` | ||
|
||
const kustomizeInstallScript = ` | ||
cd {{ .TmpDir }} | ||
curl -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v{{ .Version }}/kustomize_v{{ .Version }}_{{ .Os }}_{{ .Arch }}.tar.gz | tar xvz | ||
mv kustomize {{ .OutPath }} | ||
` | ||
|
||
const helmInstallScript = ` | ||
cd {{ .TmpDir }} | ||
curl -L https://get.helm.sh/helm-v{{ .Version }}-{{ .Os }}-{{ .Arch }}.tar.gz | tar xvz | ||
mv {{ .Os }}-{{ .Arch }}/helm {{ .OutPath }} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters