|
1 | | -package cmd |
| 1 | +package run |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "context" |
5 | 4 | "fmt" |
6 | 5 |
|
7 | 6 | "github.com/spf13/cobra" |
8 | 7 | "golang.org/x/sync/errgroup" |
9 | | - "k8s.io/apimachinery/pkg/runtime" |
10 | | - utilruntime "k8s.io/apimachinery/pkg/util/runtime" |
11 | | - "k8s.io/client-go/kubernetes" |
12 | | - "k8s.io/client-go/rest" |
13 | | - ctrl "sigs.k8s.io/controller-runtime" |
14 | | - gwapiv1 "sigs.k8s.io/gateway-api/apis/v1" |
15 | | - gwapiv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" |
16 | 8 |
|
17 | 9 | configv1alpha1 "github.com/apoxy-dev/apoxy/api/config/v1alpha1" |
18 | | - "github.com/apoxy-dev/apoxy/client/versioned" |
19 | 10 | "github.com/apoxy-dev/apoxy/config" |
20 | | - "github.com/apoxy-dev/apoxy/pkg/kube-controller/apiregistration" |
21 | | - "github.com/apoxy-dev/apoxy/pkg/kube-controller/apiserviceproxy" |
22 | | - "github.com/apoxy-dev/apoxy/pkg/kube-controller/controllers" |
23 | | - "github.com/apoxy-dev/apoxy/pkg/log" |
24 | 11 | ) |
25 | 12 |
|
26 | 13 | var runCmd = &cobra.Command{ |
@@ -62,7 +49,7 @@ Components are defined under runtime.components in the config. Example: |
62 | 49 | " mirror: \"gateway\"\n"+ |
63 | 50 | " - type: tunnel\n"+ |
64 | 51 | " tunnel:\n"+ |
65 | | - " mode: \"userspace\"\n", |
| 52 | + " mode: \"user\"\n", |
66 | 53 | config.ConfigFile) |
67 | 54 | } |
68 | 55 |
|
@@ -113,6 +100,10 @@ Components are defined under runtime.components in the config. Example: |
113 | 100 | }, |
114 | 101 | } |
115 | 102 |
|
| 103 | +func Cmd() *cobra.Command { |
| 104 | + return runCmd |
| 105 | +} |
| 106 | + |
116 | 107 | func resolveKubeMirrorConfig(in *configv1alpha1.KubeMirrorConfig) *configv1alpha1.KubeMirrorConfig { |
117 | 108 | out := in.DeepCopy() |
118 | 109 | if out.Mirror == "" { |
@@ -156,90 +147,3 @@ func validateKubeAggregationConfig(cfg *configv1alpha1.Config, ac *configv1alpha |
156 | 147 | } |
157 | 148 | return nil |
158 | 149 | } |
159 | | - |
160 | | -func runKubeAggregation(ctx context.Context, cfg *configv1alpha1.Config, ac *configv1alpha1.KubeAggregationConfig) error { |
161 | | - log.Infof("Starting kube-aggregation component (cluster=%s, namespace=%s)", |
162 | | - ac.ClusterName, ac.Namespace) |
163 | | - |
164 | | - kCluster, err := rest.InClusterConfig() |
165 | | - if err != nil { |
166 | | - return fmt.Errorf("failed to create in-cluster config: %w", err) |
167 | | - } |
168 | | - kc := kubernetes.NewForConfigOrDie(kCluster) |
169 | | - |
170 | | - var proxyOpts []apiserviceproxy.Option |
171 | | - proxyOpts = append(proxyOpts, apiserviceproxy.WithProjectID(cfg.CurrentProject.String())) |
172 | | - proxyOpts = append(proxyOpts, apiserviceproxy.WithNamespace(ac.Namespace)) |
173 | | - proxyOpts = append(proxyOpts, apiserviceproxy.WithServiceName(ac.ServiceName)) |
174 | | - if ac.ClusterName != "" { |
175 | | - proxyOpts = append(proxyOpts, apiserviceproxy.WithClusterName(ac.ClusterName)) |
176 | | - } |
177 | | - if ac.BootstrapToken != "" { |
178 | | - proxyOpts = append(proxyOpts, apiserviceproxy.WithToken(ac.BootstrapToken)) |
179 | | - } |
180 | | - if ac.APIHost != "" { |
181 | | - proxyOpts = append(proxyOpts, apiserviceproxy.WithAPIHost(ac.APIHost)) |
182 | | - } |
183 | | - |
184 | | - apiSvc, err := apiserviceproxy.NewAPIServiceProxy(ctx, kc, proxyOpts...) |
185 | | - if err != nil { |
186 | | - return fmt.Errorf("failed to create API service proxy: %w", err) |
187 | | - } |
188 | | - |
189 | | - g, ctx := errgroup.WithContext(ctx) |
190 | | - |
191 | | - g.Go(func() error { |
192 | | - log.Infof("Starting API service proxy") |
193 | | - return apiSvc.Run(ctx) |
194 | | - }) |
195 | | - |
196 | | - g.Go(func() error { |
197 | | - apiReg, err := apiregistration.NewAPIRegistration(kCluster) |
198 | | - if err != nil { |
199 | | - return fmt.Errorf("failed to create API registration client: %w", err) |
200 | | - } |
201 | | - if err := apiReg.RegisterAPIServices(ctx, ac.ServiceName, ac.Namespace, 443, apiSvc.CABundle()); err != nil { |
202 | | - return fmt.Errorf("failed to register API services: %w", err) |
203 | | - } |
204 | | - log.Infof("API services registered") |
205 | | - <-ctx.Done() |
206 | | - return nil |
207 | | - }) |
208 | | - |
209 | | - return g.Wait() |
210 | | -} |
211 | | - |
212 | | -func runKubeMirror(ctx context.Context, cfg *configv1alpha1.Config, mc *configv1alpha1.KubeMirrorConfig) error { |
213 | | - log.Infof("Starting kube-mirror component (cluster=%s, mirror=%s, namespace=%s)", |
214 | | - mc.ClusterName, mc.Mirror, mc.Namespace) |
215 | | - |
216 | | - kCluster, err := rest.InClusterConfig() |
217 | | - if err != nil { |
218 | | - return fmt.Errorf("failed to create in-cluster config: %w", err) |
219 | | - } |
220 | | - |
221 | | - scheme := runtime.NewScheme() |
222 | | - utilruntime.Must(gwapiv1.Install(scheme)) |
223 | | - utilruntime.Must(gwapiv1alpha2.Install(scheme)) |
224 | | - |
225 | | - mgr, err := ctrl.NewManager(kCluster, ctrl.Options{Scheme: scheme}) |
226 | | - if err != nil { |
227 | | - return fmt.Errorf("failed to create controller manager: %w", err) |
228 | | - } |
229 | | - |
230 | | - apoxyClient, err := versioned.NewForConfig(kCluster) |
231 | | - if err != nil { |
232 | | - return fmt.Errorf("failed to create Apoxy client: %w", err) |
233 | | - } |
234 | | - |
235 | | - reconciler := controllers.NewMirrorReconciler(mgr.GetClient(), apoxyClient, mc) |
236 | | - if err := reconciler.SetupWithManager(ctx, mgr); err != nil { |
237 | | - return fmt.Errorf("failed to setup mirror reconciler: %w", err) |
238 | | - } |
239 | | - |
240 | | - return mgr.Start(ctx) |
241 | | -} |
242 | | - |
243 | | -func init() { |
244 | | - RootCmd.AddCommand(runCmd) |
245 | | -} |
0 commit comments