removeConfigs figures out which configs in the existing spec should be kept after the update.
(flags *pflag.FlagSet, spec *swarm.ContainerSpec, credSpecName, credSpecID string)
| 857 | // removeConfigs figures out which configs in the existing spec should be kept |
| 858 | // after the update. |
| 859 | func removeConfigs(flags *pflag.FlagSet, spec *swarm.ContainerSpec, credSpecName, credSpecID string) []*swarm.ConfigReference { |
| 860 | keepConfigs := []*swarm.ConfigReference{} |
| 861 | |
| 862 | toRemove := buildToRemoveSet(flags, flagConfigRemove) |
| 863 | // all configs in spec.Configs should have both a Name and ID, because |
| 864 | // they come from an already-accepted spec. |
| 865 | for _, config := range spec.Configs { |
| 866 | // if the config is a Runtime target, make sure it's still in use right |
| 867 | // now, the only use for Runtime target is credential specs. if, in |
| 868 | // the future, more uses are added, then this check will need to be |
| 869 | // made more intelligent. |
| 870 | if config.Runtime != nil { |
| 871 | // if we're carrying over a credential spec explicitly (because the |
| 872 | // user passed --credential-spec with the same config name) then we |
| 873 | // should match on credSpecName. if we're carrying over a |
| 874 | // credential spec implicitly (because the user did not pass any |
| 875 | // --credential-spec flag) then we should match on credSpecID. in |
| 876 | // either case, we're keeping the config that already exists. |
| 877 | if config.ConfigName == credSpecName || config.ConfigID == credSpecID { |
| 878 | keepConfigs = append(keepConfigs, config) |
| 879 | } |
| 880 | // continue the loop, to skip the part where we check if the config |
| 881 | // is in toRemove. |
| 882 | continue |
| 883 | } |
| 884 | |
| 885 | if _, exists := toRemove[config.ConfigName]; !exists { |
| 886 | keepConfigs = append(keepConfigs, config) |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | return keepConfigs |
| 891 | } |
| 892 | |
| 893 | func envKey(value string) string { |
| 894 | k, _, _ := strings.Cut(value, "=") |
no test coverage detected
searching dependent graphs…