-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Very simple initial config by introducing a new Deployment `tofu`. Simply uses an initialized Workspace to apply. Since this needs an extension to 4beta11 schema introduces a new version 4beta12.
- Loading branch information
1 parent
8103806
commit 592adfa
Showing
18 changed files
with
2,930 additions
and
1 deletion.
There are no files selected for viewing
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,7 @@ | ||
apiVersion: skaffold/v4beta12 | ||
kind: Config | ||
metadata: | ||
name: tofu-test | ||
deploy: | ||
tofu: | ||
workspace: workspace |
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,7 @@ | ||
data "dns_a_record_set" "google" { | ||
host = "google.com" | ||
} | ||
|
||
output "google_addrs" { | ||
value = join(",", data.dns_a_record_set.google.addrs) | ||
} |
11 changes: 11 additions & 0 deletions
11
integration/testdata/deploy-opentofu/workspace/provider.tf
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,11 @@ | ||
terraform { | ||
required_providers { | ||
dns = { | ||
source = "hashicorp/dns" | ||
version = "3.4.2" | ||
} | ||
} | ||
} | ||
|
||
provider "dns" { | ||
} |
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,45 @@ | ||
/* | ||
Copyright 2024 The Skaffold 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 integration | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/GoogleContainerTools/skaffold/v2/integration/skaffold" | ||
) | ||
|
||
func init() { | ||
initCmd := exec.Command("tofu", "init") | ||
initCmd.Dir = "testdata/deploy-opentofu" | ||
initCmd.Run() | ||
} | ||
|
||
func TestTofuDeploy(t *testing.T) { | ||
MarkIntegrationTest(t, CanRunWithoutGcp) | ||
|
||
output := string(skaffold.Deploy().InDir("testdata/deploy-opentofu").RunOrFailOutput(t)) | ||
|
||
if !strings.Contains(output, "Apply complete!") { | ||
t.Fatal("Unexpectedly apply did not complete. Output was:", output) | ||
} | ||
|
||
if !strings.Contains(output, "google_addrs =") { | ||
t.Fatal("Output variable missing. Output was:", output) | ||
} | ||
} |
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,60 @@ | ||
/* | ||
Copyright 2024 The Skaffold 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 tofu | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
deploy "github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/deploy/types" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/instrumentation" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/tofu" | ||
) | ||
|
||
// CLI holds parameters to run tofu. | ||
type CLI struct { | ||
*tofu.CLI | ||
} | ||
|
||
type Config interface { | ||
tofu.Config | ||
deploy.Config | ||
} | ||
|
||
func NewCLI(cfg Config) CLI { | ||
return CLI{ | ||
CLI: tofu.NewCLI(cfg), | ||
} | ||
} | ||
|
||
// Apply runs `tofu apply` on a Workspace. | ||
func (c *CLI) Apply(ctx context.Context, out io.Writer) error { | ||
ctx, endTrace := instrumentation.StartTrace(ctx, "Apply", map[string]string{ | ||
"AppliedBy": "tofu", | ||
}) | ||
defer endTrace() | ||
|
||
r, w := io.Pipe() | ||
w.Close() | ||
if err := c.Run(ctx, r, out, "apply", "-auto-approve"); err != nil { | ||
endTrace(instrumentation.TraceEndError(err)) | ||
return fmt.Errorf("tofu apply: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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,158 @@ | ||
/* | ||
Copyright 2024 The Skaffold 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 tofu | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/segmentio/textio" | ||
"go.opentelemetry.io/otel/trace" | ||
|
||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/access" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/debug" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/deploy/label" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/graph" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/instrumentation" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes/manifest" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/log" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/status" | ||
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/sync" | ||
) | ||
|
||
// Deployer deploys Workspaces using tofu CLI. | ||
type Deployer struct { | ||
configName string | ||
|
||
*latest.TofuDeploy | ||
|
||
tofu CLI | ||
} | ||
|
||
// NewDeployer returns a new Deployer for a DeployConfig filled | ||
// with the needed configuration for `tofu apply` | ||
func NewDeployer(cfg Config, labeller *label.DefaultLabeller, d *latest.TofuDeploy, artifacts []*latest.Artifact, configName string) (*Deployer, error) { | ||
|
||
if d.Workspace == "" { | ||
return nil, fmt.Errorf("tofu needs Workspace to deploy from: %s", d.Workspace) | ||
} | ||
|
||
tofu := NewCLI(cfg) | ||
|
||
return &Deployer{ | ||
configName: configName, | ||
TofuDeploy: d, | ||
tofu: tofu, | ||
}, nil | ||
} | ||
|
||
func (k *Deployer) ConfigName() string { | ||
return k.configName | ||
} | ||
|
||
// GetAccessor not supported | ||
func (k *Deployer) GetAccessor() access.Accessor { | ||
return &access.NoopAccessor{} | ||
} | ||
|
||
// GetDebugger not supported. | ||
func (k *Deployer) GetDebugger() debug.Debugger { | ||
return &debug.NoopDebugger{} | ||
} | ||
|
||
// GetLogger not supported. | ||
func (k *Deployer) GetLogger() log.Logger { | ||
return &log.NoopLogger{} | ||
} | ||
|
||
// GetStatusMonitor not supported. | ||
func (k *Deployer) GetStatusMonitor() status.Monitor { | ||
return &status.NoopMonitor{} | ||
} | ||
|
||
// GetSyncer not supported. | ||
func (k *Deployer) GetSyncer() sync.Syncer { | ||
return &sync.NoopSyncer{} | ||
} | ||
|
||
// RegisterLocalImages not implemented | ||
func (k *Deployer) RegisterLocalImages(images []graph.Artifact) { | ||
} | ||
|
||
// TrackBuildArtifacts not implemented | ||
func (k *Deployer) TrackBuildArtifacts(builds, deployedImages []graph.Artifact) { | ||
} | ||
|
||
// Deploy runs `tofu apply` on Workspaces | ||
func (k *Deployer) Deploy(ctx context.Context, out io.Writer, builds []graph.Artifact, manifestsByConfig manifest.ManifestListByConfig) error { | ||
|
||
var ( | ||
childCtx context.Context | ||
endTrace func(...trace.SpanEndOption) | ||
) | ||
instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ | ||
"DeployerType": "tofu", | ||
}) | ||
|
||
childCtx, endTrace = instrumentation.StartTrace(ctx, "Deploy_TofuApply") | ||
if err := k.tofu.Apply(childCtx, textio.NewPrefixWriter(out, " - ")); err != nil { | ||
endTrace(instrumentation.TraceEndError(err)) | ||
return err | ||
} | ||
endTrace() | ||
return nil | ||
} | ||
|
||
// HasRunnableHooks not supported | ||
func (k *Deployer) HasRunnableHooks() bool { | ||
return false | ||
} | ||
|
||
// PreDeployHooks not supported | ||
func (k *Deployer) PreDeployHooks(ctx context.Context, out io.Writer) error { | ||
_, endTrace := instrumentation.StartTrace(ctx, "Deploy_PreHooks") | ||
endTrace() | ||
return nil | ||
} | ||
|
||
// PostDeployHooks not supported | ||
func (k *Deployer) PostDeployHooks(ctx context.Context, out io.Writer) error { | ||
_, endTrace := instrumentation.StartTrace(ctx, "Deploy_PostHooks") | ||
endTrace() | ||
return nil | ||
} | ||
|
||
// Cleanup deletes what was deployed by calling Deploy. | ||
func (k *Deployer) Cleanup(ctx context.Context, out io.Writer, dryRun bool, manifestsByConfig manifest.ManifestListByConfig) error { | ||
|
||
instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ | ||
"DeployerType": "tofu", | ||
}) | ||
if dryRun { | ||
return nil | ||
} | ||
// TODO: Implement delete | ||
|
||
return nil | ||
} | ||
|
||
// Dependencies lists all the files that describe what needs to be deployed. | ||
func (k *Deployer) Dependencies() ([]string, error) { | ||
return []string{}, nil | ||
} |
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
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
Oops, something went wrong.