Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
operator-controller/.tilt-support at main · operator-framework/operator-controller · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
operator-framework
operator-controller
Repository navigation
Code
Issues
13
(13)
Pull requests
15
(15)
Discussions
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
operator-controller
/
.tilt-support
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
153 lines (131 loc) · 6.59 KB
main
Breadcrumbs
operator-controller
/
.tilt-support
Copy path
Top
File metadata and controls
Code
Blame
153 lines (131 loc) · 6.59 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
load('ext://restart_process', 'docker_build_with_restart')
load('ext://cert_manager', 'deploy_cert_manager')
def deploy_cert_manager_if_needed():
cert_manager_var = '__CERT_MANAGER__'
if os.getenv(cert_manager_var) != '1':
deploy_cert_manager(version="v1.18.2")
os.putenv(cert_manager_var, '1')
# Set up our build helper image that has delve in it. We use a helper so parallel image builds don't all simultaneously
# install delve. Instead, they all wait for this build to complete, and then proceed in parallel.
docker_build(
ref='helper',
context='.',
build_args={'GO_VERSION': '1.26.3'},
dockerfile_contents='''
ARG GO_VERSION
FROM golang:${GO_VERSION}
ARG GO_VERSION
RUN CGO_ENABLED=0 go install github.com/go-delve/delve/cmd/dlv@v${GO_VERSION}
'''
)
def build_binary(repo, binary, deps, image, tags="", debug=True):
gcflags = ''
if debug:
gcflags = "-gcflags 'all=-N -l'"
# Treat the main binary as a local resource, so we can automatically rebuild it when any of the deps change. This
# builds it locally, targeting linux, so it can run in a linux container.
binary_name = binary.split("/")[-1]
local_resource(
'{}_{}_binary'.format(repo, binary_name),
cmd='''
mkdir -p .tiltbuild/bin
CGO_ENABLED=0 GOOS=linux go build {tags} {gcflags} -o .tiltbuild/bin/{binary_name} {binary}
'''.format(repo=repo, binary_name=binary_name, binary=binary, gcflags=gcflags, tags=tags),
deps=deps
)
entrypoint = ['/{}'.format(binary_name)]
if debug:
entrypoint = ['/dlv', '--accept-multiclient', '--api-version=2', '--headless=true', '--listen', ':30000', 'exec', '--continue', '--'] + entrypoint
# Configure our image build. If the file in live_update.sync (.tiltbuild/bin/$binary) changes, Tilt
# copies it to the running container and restarts it.
docker_build_with_restart(
# This has to match an image in the k8s_yaml we call below, so Tilt knows to use this image for our Deployment,
# instead of the actual image specified in the yaml.
ref='{image}:{binary_name}'.format(image=image, binary_name=binary_name),
# This is the `docker build` context, and because we're only copying in the binary we've already had Tilt build
# locally, we set the context to the directory containing the binary.
context='.tiltbuild/bin',
# We use a slimmed-down Dockerfile that only has $binary in it.
dockerfile_contents='''
FROM gcr.io/distroless/static:debug
WORKDIR /
COPY --from=helper /go/bin/dlv /
COPY {} /
'''.format(binary_name),
# The set of files Tilt should include in the build. In this case, it's just the binary we built above.
only=binary_name,
# If .tiltbuild/bin/$binary changes, Tilt will copy it into the running container and restart the process.
live_update=[
sync('.tiltbuild/bin/{}'.format(binary_name), '/{}'.format(binary_name)),
],
restart_file="/.tilt_restart_proc",
# The command to run in the container.
entrypoint=entrypoint,
)
def process_yaml(yaml):
if type(yaml) == 'string':
objects = read_yaml_stream(yaml)
elif type(yaml) == 'blob':
objects = decode_yaml_stream(yaml)
else:
fail('expected a string or blob, got: {}'.format(type(yaml)))
for o in objects:
# For Tilt's live_update functionality to work, we have to run the container as root. Remove any PSA labels
# to allow this.
if o['kind'] == 'Namespace' and 'labels' in o['metadata']:
labels_to_delete = [label for label in o['metadata']['labels'] if label.startswith('pod-security.kubernetes.io')]
for label in labels_to_delete:
o['metadata']['labels'].pop(label)
if o['kind'] != 'Deployment':
# We only need to modify Deployments, so we can skip this
continue
# For Tilt's live_update functionality to work, we have to run the container as root. Otherwise, Tilt won't
# be able to untar the updated binary in the container's file system (this is how live update
# works). If there are any securityContexts, remove them.
if "securityContext" in o['spec']['template']['spec']:
o['spec']['template']['spec'].pop('securityContext')
for c in o['spec']['template']['spec']['containers']:
if "securityContext" in c:
c.pop('securityContext')
# If multiple Deployment manifests all use the same image but use different entrypoints to change the binary,
# we have to adjust each Deployment to use a different image. Tilt needs each Deployment's image to be
# unique. We replace the tag with what is effectively :$binary, e.g. :helm.
for c in o['spec']['template']['spec']['containers']:
if c['name'] == 'kube-rbac-proxy':
continue
command = c['command'][0]
if command.startswith('./'):
command = command.removeprefix('./')
elif command.startswith('/'):
command = command.removeprefix('/')
image_without_tag = c['image'].rsplit(':', 1)[0]
# Update the image so instead of :$tag it's :$binary
c['image'] = '{}:{}'.format(image_without_tag, command)
# Now apply all the yaml
# We are using allow_duplicates=True here as both
# operator-controller and catalogd will be installed in the same
# namespace "olmv1-system" as of https://github.com/operator-framework/operator-controller/pull/888
# and https://github.com/operator-framework/catalogd/pull/283
k8s_yaml(encode_yaml_stream(objects), allow_duplicates=True)
# data format:
# {
# 'repos': {
# 'catalogd': {
# 'image': 'quay.io/operator-framework/catalogd',
# 'binary': './cmd/catalogd',
# 'deployment': 'catalogd-controller-manager',
# 'deps': ['api', 'cmd/catalogd', 'internal/catalogd', 'internal/shared', 'go.mod', 'go.sum'],
# 'starting_debug_port': 20000,
# },
# ... additional entries here ...
# },
# 'yaml': 'config/overlays/tilt-local-dev',
# }
def deploy_repo(data, tags="", debug=True):
deploy_cert_manager_if_needed()
for reponame, repo in data['repos'].items():
print('Deploying repo {}'.format(reponame))
local_port = repo['starting_debug_port']
build_binary(reponame, repo['binary'], repo['deps'], repo['image'], tags, debug)
k8s_resource(repo['deployment'], port_forwards=['{}:30000'.format(local_port)])
process_yaml(helm('helm/olmv1', name="olmv1", values=[data['yaml']]))
You can’t perform that action at this time.