(ctx resource.Context, originalCfg echo.Config)
| 63 | } |
| 64 | |
| 65 | func newInstance(ctx resource.Context, originalCfg echo.Config) (out *instance, err error) { |
| 66 | cfg := originalCfg.DeepCopy() |
| 67 | |
| 68 | c := &instance{ |
| 69 | cfg: cfg, |
| 70 | ctx: ctx, |
| 71 | cluster: cfg.Cluster, |
| 72 | } |
| 73 | |
| 74 | // Deploy echo to the cluster |
| 75 | c.deployment, err = newDeployment(ctx, cfg) |
| 76 | if err != nil { |
| 77 | return nil, err |
| 78 | } |
| 79 | |
| 80 | // Create the manager for echo workloads for this instance. |
| 81 | c.workloadMgr, err = newWorkloadManager(ctx, cfg, c.deployment) |
| 82 | if err != nil { |
| 83 | return nil, err |
| 84 | } |
| 85 | |
| 86 | // Now that we have the successfully created the workload manager, track this resource so |
| 87 | // that it will be closed when it goes out of scope. |
| 88 | c.id = ctx.TrackResource(c) |
| 89 | |
| 90 | // Now retrieve the service information to find the ClusterIP |
| 91 | s, err := c.cluster.Kube().CoreV1().Services(cfg.Namespace.Name()).Get(context.TODO(), cfg.Service, metav1.GetOptions{}) |
| 92 | if err != nil { |
| 93 | return nil, err |
| 94 | } |
| 95 | |
| 96 | c.clusterIP = s.Spec.ClusterIP |
| 97 | c.clusterIPs = s.Spec.ClusterIPs |
| 98 | switch c.clusterIP { |
| 99 | case corev1.ClusterIPNone, "": |
| 100 | if !cfg.Headless { |
| 101 | return nil, fmt.Errorf("invalid ClusterIP %s for non-headless service %s/%s", |
| 102 | c.clusterIP, |
| 103 | c.cfg.Namespace.Name(), |
| 104 | c.cfg.Service) |
| 105 | } |
| 106 | c.clusterIP = "" |
| 107 | } |
| 108 | |
| 109 | // Start the workload manager. |
| 110 | if err := c.workloadMgr.Start(); err != nil { |
| 111 | return nil, err |
| 112 | } |
| 113 | |
| 114 | return c, nil |
| 115 | } |
| 116 | |
| 117 | func (c *instance) ID() resource.ID { |
| 118 | return c.id |
no test coverage detected
searching dependent graphs…