-
Notifications
You must be signed in to change notification settings - Fork 1.8k
commands,pkg/scaffold,hack,pkg/helm: run and migrate command support for helm #897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joelanford
merged 7 commits into
operator-framework:master
from
joelanford:helm-run-migrate
Jan 15, 2019
+569
−208
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9dd86f0
[travis deploy] commands,pkg/scaffold,hack,pkg/helm: run and migrate …
joelanford 070eebe
Merge branch 'master' into helm-run-migrate
joelanford 41db5fd
Merge branch 'master' into helm-run-migrate
joelanford 6d0f7e0
CHANGELOG.md,doc,commands/.../run/helm.go: document helm support for …
joelanford e09a89c
Merge branch 'master' into helm-run-migrate
joelanford 8ce2ff5
doc/dev/testing/travis-build.md: ansible/helm e2e doc update
joelanford 04501f8
doc/dev/release.md: documenting new release steps for ansible/helm go…
joelanford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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,40 @@ | ||
// Copyright 2019 The Operator-SDK 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 run | ||
|
||
import ( | ||
"github.com/operator-framework/operator-sdk/pkg/helm" | ||
hoflags "github.com/operator-framework/operator-sdk/pkg/helm/flags" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// NewHelmCmd returns a command that will run a helm operator | ||
func NewHelmCmd() *cobra.Command { | ||
var flags *hoflags.HelmOperatorFlags | ||
newCmd := &cobra.Command{ | ||
Use: "helm", | ||
Short: "Runs as a helm operator", | ||
Long: `Runs as a helm operator. This is intended to be used when running | ||
in a Pod inside a cluster. Developers wanting to run their operator locally | ||
should use "up local" instead.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
helm.Run(flags) | ||
}, | ||
} | ||
flags = hoflags.AddTo(newCmd.Flags()) | ||
|
||
return newCmd | ||
} |
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
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
File renamed without changes.
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
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 2019 The Operator-SDK 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 main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/operator-framework/operator-sdk/internal/util/projutil" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/helm" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
// main renders scaffolds that are required to build the helm operator base | ||
// image. It is intended for release engineering use only. After running this, | ||
// you can place a binary in `build/_output/bin/helm-operator` and then run | ||
// `operator-sdk build`. | ||
func main() { | ||
cfg := &input.Config{ | ||
AbsProjectPath: projutil.MustGetwd(), | ||
ProjectName: "helm-operator", | ||
} | ||
|
||
s := &scaffold.Scaffold{} | ||
err := s.Execute(cfg, | ||
&helm.DockerfileHybrid{}, | ||
&helm.Entrypoint{}, | ||
&helm.UserSetup{}, | ||
) | ||
if err != nil { | ||
log.Fatalf("add scaffold failed: (%v)", err) | ||
} | ||
} |
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
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,64 @@ | ||
// Copyright 2019 The Operator-SDK 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 helm | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/scaffold" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
//DockerfileHybrid - Dockerfile for a hybrid operator | ||
type DockerfileHybrid struct { | ||
input.Input | ||
|
||
// HelmCharts - if true, include a COPY statement for the helm-charts directory | ||
HelmCharts bool | ||
|
||
// Watches - if true, include a COPY statement for watches.yaml | ||
Watches bool | ||
} | ||
|
||
// GetInput - gets the input | ||
func (d *DockerfileHybrid) GetInput() (input.Input, error) { | ||
if d.Path == "" { | ||
d.Path = filepath.Join(scaffold.BuildDir, scaffold.DockerfileFile) | ||
} | ||
d.TemplateBody = dockerFileHybridHelmTmpl | ||
return d.Input, nil | ||
} | ||
|
||
const dockerFileHybridHelmTmpl = `FROM alpine:3.6 | ||
ENV OPERATOR=/usr/local/bin/helm-operator \ | ||
USER_UID=1001 \ | ||
USER_NAME=helm \ | ||
HOME=/opt/helm | ||
# install operator binary | ||
COPY build/_output/bin/{{.ProjectName}} ${OPERATOR} | ||
COPY bin /usr/local/bin | ||
RUN /usr/local/bin/user_setup | ||
{{- if .HelmCharts }} | ||
COPY helm-charts/ ${HOME}/helm-charts/{{ end }} | ||
{{- if .Watches }} | ||
COPY watches.yaml ${HOME}/watches.yaml{{ end }} | ||
ENTRYPOINT ["/usr/local/bin/entrypoint"] | ||
USER ${USER_UID}` |
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,49 @@ | ||
// Copyright 2019 The Operator-SDK 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 helm | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
// Entrypoint - entrypoint script | ||
type Entrypoint struct { | ||
input.Input | ||
} | ||
|
||
func (e *Entrypoint) GetInput() (input.Input, error) { | ||
if e.Path == "" { | ||
e.Path = filepath.Join("bin", "entrypoint") | ||
} | ||
e.TemplateBody = entrypointTmpl | ||
e.IsExec = true | ||
return e.Input, nil | ||
} | ||
|
||
const entrypointTmpl = `#!/bin/sh -e | ||
# This is documented here: | ||
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines | ||
if ! whoami &>/dev/null; then | ||
if [ -w /etc/passwd ]; then | ||
echo "${USER_NAME:-helm}:x:$(id -u):$(id -g):${USER_NAME:-helm} user:${HOME}:/sbin/nologin" >> /etc/passwd | ||
fi | ||
fi | ||
exec ${OPERATOR} run helm --watches-file=/opt/helm/watches.yaml $@ | ||
` |
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,44 @@ | ||
// Copyright 2019 The Operator-SDK 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 helm | ||
|
||
import ( | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold" | ||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
// GopkgToml - the Gopkg.toml file for a hybrid operator | ||
type GopkgToml struct { | ||
input.Input | ||
} | ||
|
||
func (s *GopkgToml) GetInput() (input.Input, error) { | ||
if s.Path == "" { | ||
s.Path = scaffold.GopkgTomlFile | ||
} | ||
s.TemplateBody = gopkgTomlTmpl | ||
return s.Input, nil | ||
} | ||
|
||
const gopkgTomlTmpl = `[[constraint]] | ||
name = "github.com/operator-framework/operator-sdk" | ||
# The version rule is used for a specific release and the master branch for in between releases. | ||
branch = "master" #osdk_branch_annotation | ||
# version = "=v0.3.0" #osdk_version_annotation | ||
[prune] | ||
go-tests = true | ||
unused-packages = true | ||
` |
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,51 @@ | ||
// Copyright 2019 The Operator-SDK 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 helm | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
// Main - main source file for helm operator | ||
type Main struct { | ||
input.Input | ||
} | ||
|
||
func (m *Main) GetInput() (input.Input, error) { | ||
if m.Path == "" { | ||
m.Path = filepath.Join("cmd", "manager", "main.go") | ||
} | ||
m.TemplateBody = mainTmpl | ||
return m.Input, nil | ||
} | ||
|
||
const mainTmpl = `package main | ||
import ( | ||
hoflags "github.com/operator-framework/operator-sdk/pkg/helm/flags" | ||
"github.com/operator-framework/operator-sdk/pkg/helm" | ||
"github.com/spf13/pflag" | ||
) | ||
func main() { | ||
hflags := hoflags.AddTo(pflag.CommandLine) | ||
pflag.Parse() | ||
helm.Run(hflags) | ||
} | ||
` |
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,50 @@ | ||
// Copyright 2019 The Operator-SDK 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 helm | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/scaffold/input" | ||
) | ||
|
||
// UserSetup - userSetup script | ||
type UserSetup struct { | ||
input.Input | ||
} | ||
|
||
func (u *UserSetup) GetInput() (input.Input, error) { | ||
if u.Path == "" { | ||
u.Path = filepath.Join("bin", "user_setup") | ||
} | ||
u.TemplateBody = userSetupTmpl | ||
u.IsExec = true | ||
return u.Input, nil | ||
} | ||
|
||
const userSetupTmpl = `#!/bin/sh | ||
set -x | ||
# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be) | ||
mkdir -p ${HOME} | ||
chown ${USER_UID}:0 ${HOME} | ||
chmod ug+rwx ${HOME} | ||
# runtime user will need to be able to self-insert in /etc/passwd | ||
chmod g+rw /etc/passwd | ||
# no need for this script to remain in the image after running | ||
rm $0 | ||
` |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just remembered that we need to update this scaffold for each release as well now.
@joelanford Can you please update the release guide section for the version update as well.
We need to bump both
pkg/scaffold/ansible/gopkgtoml.go
and this filepkg/scaffold/helm/gopkgtoml.go
@estroz We just need to add checks for these two files in the release.sh script to ensure the versions are set correctly at release time as well right? Similar to the existing checks:
https://github.com/operator-framework/operator-sdk/blob/master/release.sh#L38-L41
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estroz scratch that. I just saw @joelanford already added the check for this file down in release.sh.