Skip to content

Commit

Permalink
Merge "Implement document rendering sub-command"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed May 27, 2020
2 parents 5823514 + 6d05ae6 commit 88542a6
Show file tree
Hide file tree
Showing 25 changed files with 587 additions and 53 deletions.
1 change: 0 additions & 1 deletion cmd/document/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func NewDocumentCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Com
}

documentRootCmd.AddCommand(NewPullCommand(rootSettings))
documentRootCmd.AddCommand(NewRenderCommand(rootSettings))
documentRootCmd.AddCommand(NewPluginCommand(rootSettings))

return documentRootCmd
Expand Down
5 changes: 0 additions & 5 deletions cmd/document/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ func TestDocument(t *testing.T) {
CmdLine: "-h",
Cmd: document.NewDocumentCommand(nil),
},
{
Name: "document-render-with-help",
CmdLine: "-h",
Cmd: document.NewRenderCommand(nil),
},
{
Name: "document-plugin-with-help",
CmdLine: "-h",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Available Commands:
help Help about any command
plugin Run as a kustomize exec plugin
pull Pulls documents from remote git repository
render Render documents from model

Flags:
-h, --help help for document
Expand Down
1 change: 1 addition & 0 deletions cmd/phase/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewPhaseCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comman
}

phaseRootCmd.AddCommand(NewApplyCommand(rootSettings, client.DefaultClient))
phaseRootCmd.AddCommand(NewRenderCommand(rootSettings))

return phaseRootCmd
}
54 changes: 32 additions & 22 deletions cmd/document/render.go → cmd/phase/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,41 @@
limitations under the License.
*/

package document
package phase

import (
"github.com/spf13/cobra"

"opendev.org/airship/airshipctl/pkg/document/render"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/pkg/errors"
"opendev.org/airship/airshipctl/pkg/phase/render"
)

const (
renderExample = `
# Get all 'initinfra' phase documents containing labels "app=helm" and
# "service=tiller"
airshipctl phase render initinfra -l app=helm,service=tiller
# Get all documents containing labels "app=helm" and "service=tiller"
# and kind 'Deployment'
airshipctl phase render initinfra -l app=helm,service=tiller -k Deployment
`
)

// NewRenderCommand create a new command for document rendering
func NewRenderCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
renderSettings := &render.Settings{AirshipCTLSettings: rootSettings}
renderCmd := &cobra.Command{
Use: "render",
Short: "Render documents from model",
Use: "render PHASE_NAME",
Short: "Render phase documents from model",
Example: renderExample,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return errors.ErrNotImplemented{}
path, err := renderSettings.Config.CurrentContextEntryPoint(args[0])
if err != nil {
return err
}
return renderSettings.Render(path, cmd.OutOrStdout())
},
}

Expand All @@ -41,38 +58,31 @@ func NewRenderCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Comma
func addRenderFlags(settings *render.Settings, cmd *cobra.Command) {
flags := cmd.Flags()

flags.StringArrayVarP(
flags.StringVarP(
&settings.Label,
"label",
"l",
nil,
"",
"filter documents by Labels")

flags.StringArrayVarP(
flags.StringVarP(
&settings.Annotation,
"annotation",
"a",
nil,
"",
"filter documents by Annotations")

flags.StringArrayVarP(
&settings.GroupVersion,
flags.StringVarP(
&settings.APIVersion,
"apiversion",
"g",
nil,
"",
"filter documents by API version")

flags.StringArrayVarP(
flags.StringVarP(
&settings.Kind,
"kind",
"k",
nil,
"filter documents by Kinds")

flags.StringVarP(
&settings.RawFilter,
"filter",
"f",
"",
"logical expression for document filtering")
"filter documents by Kinds")
}
61 changes: 61 additions & 0 deletions cmd/phase/render_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
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
https://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 phase_test

import (
"testing"

"github.com/stretchr/testify/require"

"opendev.org/airship/airshipctl/cmd/phase"
"opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/pkg/environment"
"opendev.org/airship/airshipctl/testutil"
)

func TestRender(t *testing.T) {
cfg, cleanupCfg := testutil.InitConfig(t)
defer cleanupCfg(t)
cfg.CurrentContext = "def_ephemeral"
cfg.Manifests["test"] = &config.Manifest{
TargetPath: "testdata",
PrimaryRepositoryName: "testRepo",
Repositories: map[string]*config.Repository{
"testRepo": {
URLString: "http://localhost",
},
},
}
ctx, err := cfg.GetContext("def_ephemeral")
require.NoError(t, err)
ctx.Manifest = "test"
settings := &environment.AirshipCTLSettings{Config: cfg}

tests := []*testutil.CmdTest{
{
Name: "render-with-help",
CmdLine: "-h",
Cmd: phase.NewRenderCommand(nil),
},
{
Name: "render-with-multiple-labels",
CmdLine: "initinfra -l app=helm,name=tiller",
Cmd: phase.NewRenderCommand(settings),
},
}
for _, tt := range tests {
testutil.RunTest(t, tt)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Usage:
Available Commands:
apply Apply phase to a cluster
help Help about any command
render Render phase documents from model

Flags:
-h, --help help for phase
Expand Down
22 changes: 22 additions & 0 deletions cmd/phase/testdata/TestRenderGoldenOutput/render-with-help.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Render phase documents from model

Usage:
render PHASE_NAME [flags]

Examples:

# Get all 'initinfra' phase documents containing labels "app=helm" and
# "service=tiller"
airshipctl phase render initinfra -l app=helm,service=tiller

# Get all documents containing labels "app=helm" and "service=tiller"
# and kind 'Deployment'
airshipctl phase render initinfra -l app=helm,service=tiller -k Deployment


Flags:
-a, --annotation string filter documents by Annotations
-g, --apiversion string filter documents by API version
-h, --help help for render
-k, --kind string filter documents by Kinds
-l, --label string filter documents by Labels
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
airshipit.org/clustertype: ephemeral
creationTimestamp: null
labels:
app: helm
name: tiller
name: tiller-deploy
namespace: kube-system
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: helm
name: tiller
spec:
automountServiceAccountToken: true
containers:
- env:
- name: TILLER_NAMESPACE
value: kube-system
- name: TILLER_HISTORY_MAX
value: "0"
image: gcr.io/kubernetes-helm/tiller:v2.12.3
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /liveness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
name: tiller
ports:
- containerPort: 44134
name: tiller
- containerPort: 44135
name: http
readinessProbe:
httpGet:
path: /readiness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
resources: {}
status: {}
...
2 changes: 2 additions & 0 deletions cmd/phase/testdata/ephemeral/initinfra/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- tiller.yaml
74 changes: 74 additions & 0 deletions cmd/phase/testdata/ephemeral/initinfra/tiller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
airshipit.org/clustertype: ephemeral
creationTimestamp: null
labels:
app: helm
name: tiller
name: tiller-deploy
namespace: kube-system
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: helm
name: tiller
spec:
automountServiceAccountToken: true
containers:
- env:
- name: TILLER_NAMESPACE
value: kube-system
- name: TILLER_HISTORY_MAX
value: "0"
image: gcr.io/kubernetes-helm/tiller:v2.12.3
imagePullPolicy: IfNotPresent
livenessProbe:
httpGet:
path: /liveness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
name: tiller
ports:
- containerPort: 44134
name: tiller
- containerPort: 44135
name: http
readinessProbe:
httpGet:
path: /readiness
port: 44135
initialDelaySeconds: 1
timeoutSeconds: 1
resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
annotations:
airshipit.org/clustertype: ephemeral
creationTimestamp: null
labels:
app: helm
name: tiller-deploy
namespace: kube-system
spec:
ports:
- name: tiller
port: 44134
targetPort: tiller
selector:
app: helm
name: tiller
type: ClusterIP
status:
loadBalancer: {}
...
1 change: 0 additions & 1 deletion docs/source/cli/airshipctl_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ such as getting status and deploying initial infrastructure.

* [airshipctl](airshipctl.md) - A unified entrypoint to various airship components
* [airshipctl cluster init](airshipctl_cluster_init.md) - Deploy cluster-api provider components
* [airshipctl cluster initinfra](airshipctl_cluster_initinfra.md) - Deploy initinfra components to cluster

1 change: 0 additions & 1 deletion docs/source/cli/airshipctl_document.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ Manage deployment documents
* [airshipctl](airshipctl.md) - A unified entrypoint to various airship components
* [airshipctl document plugin](airshipctl_document_plugin.md) - Run as a kustomize exec plugin
* [airshipctl document pull](airshipctl_document_pull.md) - Pulls documents from remote git repository
* [airshipctl document render](airshipctl_document_render.md) - Render documents from model

1 change: 1 addition & 0 deletions docs/source/cli/airshipctl_phase.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ such as getting list and applying specific one.

* [airshipctl](airshipctl.md) - A unified entrypoint to various airship components
* [airshipctl phase apply](airshipctl_phase_apply.md) - Apply phase to a cluster
* [airshipctl phase render](airshipctl_phase_render.md) - Render phase documents from model

Loading

0 comments on commit 88542a6

Please sign in to comment.