mirror of https://github.com/kubernetes/kops.git
Merge pull request #14927 from justinsb/ensuretask_should_panic
EnsureTask should panic
This commit is contained in:
commit
fbdabc1c16
|
|
@ -294,10 +294,7 @@ func (c *NodeupModelContext) BuildBootstrapKubeconfig(name string, ctx *fi.Nodeu
|
||||||
kubeConfig.ServerURL = "https://" + c.APIInternalName()
|
kubeConfig.ServerURL = "https://" + c.APIInternalName()
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ctx.EnsureTask(kubeConfig)
|
ctx.EnsureTask(kubeConfig)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return kubeConfig.GetConfig(), nil
|
return kubeConfig.GetConfig(), nil
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -115,10 +115,7 @@ func (b *KubeletBuilder) Build(c *fi.NodeupModelBuilderContext) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.EnsureTask(t)
|
c.EnsureTask(t)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -520,9 +520,7 @@ func (b *APILoadBalancerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
||||||
ID: fi.PtrTo(id),
|
ID: fi.PtrTo(id),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
if err := c.EnsureTask(t); err != nil {
|
c.EnsureTask(t)
|
||||||
return err
|
|
||||||
}
|
|
||||||
clb.SecurityGroups = append(clb.SecurityGroups, t)
|
clb.SecurityGroups = append(clb.SecurityGroups, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -354,9 +354,7 @@ func (b *AutoscalingGroupModelBuilder) buildSecurityGroups(c *fi.CloudupModelBui
|
||||||
Name: fi.PtrTo("nlb-" + id),
|
Name: fi.PtrTo("nlb-" + id),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
if err := c.EnsureTask(sgTask); err != nil {
|
c.EnsureTask(sgTask)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
securityGroups = append(securityGroups, sgTask)
|
securityGroups = append(securityGroups, sgTask)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -369,9 +367,7 @@ func (b *AutoscalingGroupModelBuilder) buildSecurityGroups(c *fi.CloudupModelBui
|
||||||
Name: fi.PtrTo(id),
|
Name: fi.PtrTo(id),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
if err := c.EnsureTask(sgTask); err != nil {
|
c.EnsureTask(sgTask)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
securityGroups = append(securityGroups, sgTask)
|
securityGroups = append(securityGroups, sgTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -480,9 +476,7 @@ func (b *AutoscalingGroupModelBuilder) buildAutoScalingGroupTask(c *fi.CloudupMo
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
t.LoadBalancers = append(t.LoadBalancers, lb)
|
t.LoadBalancers = append(t.LoadBalancers, lb)
|
||||||
if err := c.EnsureTask(lb); err != nil {
|
c.EnsureTask(lb)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if extLB.TargetGroupARN != nil {
|
if extLB.TargetGroupARN != nil {
|
||||||
|
|
@ -497,9 +491,7 @@ func (b *AutoscalingGroupModelBuilder) buildAutoScalingGroupTask(c *fi.CloudupMo
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
t.TargetGroups = append(t.TargetGroups, tg)
|
t.TargetGroups = append(t.TargetGroups, tg)
|
||||||
if err := c.EnsureTask(tg); err != nil {
|
c.EnsureTask(tg)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Stable(awstasks.OrderLoadBalancersByName(t.LoadBalancers))
|
sort.Stable(awstasks.OrderLoadBalancersByName(t.LoadBalancers))
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,8 @@ func (b *DNSModelBuilder) ensureDNSZone(c *fi.CloudupModelBuilderContext) error
|
||||||
dnsZone.DNSName = fi.PtrTo(b.Cluster.Spec.DNSZone)
|
dnsZone.DNSName = fi.PtrTo(b.Cluster.Spec.DNSZone)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.EnsureTask(dnsZone)
|
c.EnsureTask(dnsZone)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *DNSModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
func (b *DNSModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
||||||
|
|
@ -131,7 +132,7 @@ func (b *DNSModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
||||||
|
|
||||||
// Using EnsureTask as APIInternalName() and APIPublicName could be the same
|
// Using EnsureTask as APIInternalName() and APIPublicName could be the same
|
||||||
{
|
{
|
||||||
err := c.EnsureTask(&awstasks.DNSName{
|
c.EnsureTask(&awstasks.DNSName{
|
||||||
Name: fi.PtrTo(b.Cluster.APIInternalName()),
|
Name: fi.PtrTo(b.Cluster.APIInternalName()),
|
||||||
ResourceName: fi.PtrTo(b.Cluster.APIInternalName()),
|
ResourceName: fi.PtrTo(b.Cluster.APIInternalName()),
|
||||||
Lifecycle: b.Lifecycle,
|
Lifecycle: b.Lifecycle,
|
||||||
|
|
@ -139,12 +140,9 @@ func (b *DNSModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
||||||
ResourceType: fi.PtrTo("A"),
|
ResourceType: fi.PtrTo("A"),
|
||||||
TargetLoadBalancer: targetLoadBalancer,
|
TargetLoadBalancer: targetLoadBalancer,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if b.UseIPv6ForAPI() {
|
if b.UseIPv6ForAPI() {
|
||||||
err := c.EnsureTask(&awstasks.DNSName{
|
c.EnsureTask(&awstasks.DNSName{
|
||||||
Name: fi.PtrTo(b.Cluster.APIInternalName() + "-AAAA"),
|
Name: fi.PtrTo(b.Cluster.APIInternalName() + "-AAAA"),
|
||||||
ResourceName: fi.PtrTo(b.Cluster.APIInternalName()),
|
ResourceName: fi.PtrTo(b.Cluster.APIInternalName()),
|
||||||
Lifecycle: b.Lifecycle,
|
Lifecycle: b.Lifecycle,
|
||||||
|
|
@ -152,9 +150,6 @@ func (b *DNSModelBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
||||||
ResourceType: fi.PtrTo("AAAA"),
|
ResourceType: fi.PtrTo("AAAA"),
|
||||||
TargetLoadBalancer: targetLoadBalancer,
|
TargetLoadBalancer: targetLoadBalancer,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -666,10 +666,7 @@ func addAdditionalRoutes(routes []kops.RouteSpec, sbName string, rt *awstasks.Ro
|
||||||
ID: fi.PtrTo(r.Target),
|
ID: fi.PtrTo(r.Target),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
err := c.EnsureTask(inst)
|
c.EnsureTask(inst)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.Instance = inst
|
t.Instance = inst
|
||||||
c.AddTask(t)
|
c.AddTask(t)
|
||||||
} else if strings.HasPrefix(r.Target, "nat-") {
|
} else if strings.HasPrefix(r.Target, "nat-") {
|
||||||
|
|
@ -679,10 +676,7 @@ func addAdditionalRoutes(routes []kops.RouteSpec, sbName string, rt *awstasks.Ro
|
||||||
ID: fi.PtrTo(r.Target),
|
ID: fi.PtrTo(r.Target),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
err := c.EnsureTask(nat)
|
c.EnsureTask(nat)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.NatGateway = nat
|
t.NatGateway = nat
|
||||||
c.AddTask(t)
|
c.AddTask(t)
|
||||||
} else if strings.HasPrefix(r.Target, "tgw-") {
|
} else if strings.HasPrefix(r.Target, "tgw-") {
|
||||||
|
|
@ -695,10 +689,7 @@ func addAdditionalRoutes(routes []kops.RouteSpec, sbName string, rt *awstasks.Ro
|
||||||
ID: fi.PtrTo(r.Target),
|
ID: fi.PtrTo(r.Target),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
err := c.EnsureTask(internetGW)
|
c.EnsureTask(internetGW)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.InternetGateway = internetGW
|
t.InternetGateway = internetGW
|
||||||
c.AddTask(t)
|
c.AddTask(t)
|
||||||
} else if strings.HasPrefix(r.Target, "eigw-") {
|
} else if strings.HasPrefix(r.Target, "eigw-") {
|
||||||
|
|
@ -708,10 +699,7 @@ func addAdditionalRoutes(routes []kops.RouteSpec, sbName string, rt *awstasks.Ro
|
||||||
ID: fi.PtrTo(r.Target),
|
ID: fi.PtrTo(r.Target),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
err := c.EnsureTask(eigw)
|
c.EnsureTask(eigw)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.EgressOnlyInternetGateway = eigw
|
t.EgressOnlyInternetGateway = eigw
|
||||||
c.AddTask(t)
|
c.AddTask(t)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -640,9 +640,7 @@ func (b *SpotInstanceGroupModelBuilder) buildSecurityGroups(c *fi.CloudupModelBu
|
||||||
Name: fi.PtrTo(id),
|
Name: fi.PtrTo(id),
|
||||||
Shared: fi.PtrTo(true),
|
Shared: fi.PtrTo(true),
|
||||||
}
|
}
|
||||||
if err := c.EnsureTask(sg); err != nil {
|
c.EnsureTask(sg)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
securityGroups = append(securityGroups, sg)
|
securityGroups = append(securityGroups, sg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,14 +129,12 @@ func (b *EtcdManagerBuilder) Build(c *fi.CloudupModelBuilderContext) error {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Because API server can only have a single client-cert, we need to share a client CA
|
// Because API server can only have a single client-cert, we need to share a client CA
|
||||||
if err := c.EnsureTask(&fitasks.Keypair{
|
c.EnsureTask(&fitasks.Keypair{
|
||||||
Name: fi.PtrTo("etcd-clients-ca"),
|
Name: fi.PtrTo("etcd-clients-ca"),
|
||||||
Lifecycle: b.Lifecycle,
|
Lifecycle: b.Lifecycle,
|
||||||
Subject: "cn=etcd-clients-ca",
|
Subject: "cn=etcd-clients-ca",
|
||||||
Type: "ca",
|
Type: "ca",
|
||||||
}); err != nil {
|
})
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if etcdCluster.Name == "cilium" {
|
if etcdCluster.Name == "cilium" {
|
||||||
clientsCaCilium := &fitasks.Keypair{
|
clientsCaCilium := &fitasks.Keypair{
|
||||||
|
|
|
||||||
|
|
@ -89,14 +89,11 @@ func (i *IssueCert) GetResources() (certResource, keyResource, caResource *fi.No
|
||||||
|
|
||||||
func (i *IssueCert) AddFileTasks(c *fi.NodeupModelBuilderContext, dir string, name string, caName string, owner *string) error {
|
func (i *IssueCert) AddFileTasks(c *fi.NodeupModelBuilderContext, dir string, name string, caName string, owner *string) error {
|
||||||
certResource, keyResource, caResource := i.GetResources()
|
certResource, keyResource, caResource := i.GetResources()
|
||||||
err := c.EnsureTask(&File{
|
c.EnsureTask(&File{
|
||||||
Path: dir,
|
Path: dir,
|
||||||
Type: FileType_Directory,
|
Type: FileType_Directory,
|
||||||
Mode: fi.PtrTo("0755"),
|
Mode: fi.PtrTo("0755"),
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.AddTask(&File{
|
c.AddTask(&File{
|
||||||
Path: filepath.Join(dir, name+".crt"),
|
Path: filepath.Join(dir, name+".crt"),
|
||||||
|
|
@ -115,16 +112,13 @@ func (i *IssueCert) AddFileTasks(c *fi.NodeupModelBuilderContext, dir string, na
|
||||||
})
|
})
|
||||||
|
|
||||||
if caName != "" {
|
if caName != "" {
|
||||||
err = c.EnsureTask(&File{
|
c.EnsureTask(&File{
|
||||||
Path: filepath.Join(dir, caName+".crt"),
|
Path: filepath.Join(dir, caName+".crt"),
|
||||||
Contents: caResource,
|
Contents: caResource,
|
||||||
Type: FileType_File,
|
Type: FileType_File,
|
||||||
Mode: fi.PtrTo("0644"),
|
Mode: fi.PtrTo("0644"),
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,9 @@ func (c *ModelBuilderContext[T]) AddTask(task Task[T]) {
|
||||||
// EnsureTask ensures that the specified task is configured.
|
// EnsureTask ensures that the specified task is configured.
|
||||||
// It adds the task if it does not already exist.
|
// It adds the task if it does not already exist.
|
||||||
// If it does exist, it verifies that the existing task reflect.DeepEqual the new task,
|
// If it does exist, it verifies that the existing task reflect.DeepEqual the new task,
|
||||||
// if they are different an error is returned.
|
// if they are different we panic; otherwise it's too easy to forget to check the error code,
|
||||||
func (c *ModelBuilderContext[T]) EnsureTask(task Task[T]) error {
|
// and realistically we have yet to find a scenario where we can recover from an error here.
|
||||||
|
func (c *ModelBuilderContext[T]) EnsureTask(task Task[T]) {
|
||||||
task = c.setLifecycleOverride(task)
|
task = c.setLifecycleOverride(task)
|
||||||
key := buildTaskKey(task)
|
key := buildTaskKey(task)
|
||||||
|
|
||||||
|
|
@ -147,16 +148,17 @@ func (c *ModelBuilderContext[T]) EnsureTask(task Task[T]) error {
|
||||||
if found {
|
if found {
|
||||||
if reflect.DeepEqual(task, existing) {
|
if reflect.DeepEqual(task, existing) {
|
||||||
klog.V(8).Infof("EnsureTask ignoring identical ")
|
klog.V(8).Infof("EnsureTask ignoring identical ")
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
klog.Warningf("EnsureTask found task mismatch for %q", key)
|
klog.Warningf("EnsureTask found task mismatch for %q", key)
|
||||||
klog.Warningf("\tExisting: %v", existing)
|
klog.Warningf("\tExisting: %v", existing)
|
||||||
klog.Warningf("\tNew: %v", task)
|
klog.Warningf("\tNew: %v", task)
|
||||||
|
|
||||||
return fmt.Errorf("cannot add different task with same key %q", key)
|
// c.Errorf("cannot add different task with same key %q", key)
|
||||||
|
klog.Fatalf("cannot add different task with same key %q", key)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
c.Tasks[key] = task
|
c.Tasks[key] = task
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setLifecycleOverride determines if a Lifecycle is in the LifecycleOverrides map for the current task.
|
// setLifecycleOverride determines if a Lifecycle is in the LifecycleOverrides map for the current task.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue