ParseConfig parses the JSON load balancer config provided into an internal form or returns an error if the config is invalid. When parsing a config update, the following validations are performed: - routeLookupConfig: - grpc_keybuilders field: - must have at least one entry - mu
(c json.RawMessage)
| 143 | // - childPolicyConfigTargetFieldName: |
| 144 | // - must be set and non-empty |
| 145 | func (rlsBB) ParseConfig(c json.RawMessage) (serviceconfig.LoadBalancingConfig, error) { |
| 146 | if logger.V(2) { |
| 147 | logger.Infof("Received JSON service config: %v", pretty.ToJSON(c)) |
| 148 | } |
| 149 | |
| 150 | cfgJSON := &lbConfigJSON{} |
| 151 | if err := json.Unmarshal(c, cfgJSON); err != nil { |
| 152 | return nil, fmt.Errorf("rls: json unmarshal failed for service config %+v: %v", string(c), err) |
| 153 | } |
| 154 | |
| 155 | m := protojson.UnmarshalOptions{DiscardUnknown: true} |
| 156 | rlsProto := &rlspb.RouteLookupConfig{} |
| 157 | if err := m.Unmarshal(cfgJSON.RouteLookupConfig, rlsProto); err != nil { |
| 158 | return nil, fmt.Errorf("rls: bad RouteLookupConfig proto %+v: %v", string(cfgJSON.RouteLookupConfig), err) |
| 159 | } |
| 160 | lbCfg, err := parseRLSProto(rlsProto) |
| 161 | if err != nil { |
| 162 | return nil, err |
| 163 | } |
| 164 | |
| 165 | if sc := string(cfgJSON.RouteLookupChannelServiceConfig); sc != "" { |
| 166 | parsed := internal.ParseServiceConfig.(func(string) *serviceconfig.ParseResult)(sc) |
| 167 | if parsed.Err != nil { |
| 168 | return nil, fmt.Errorf("rls: bad control channel service config %q: %v", sc, parsed.Err) |
| 169 | } |
| 170 | lbCfg.controlChannelServiceConfig = sc |
| 171 | } |
| 172 | |
| 173 | if cfgJSON.ChildPolicyConfigTargetFieldName == "" { |
| 174 | return nil, fmt.Errorf("rls: childPolicyConfigTargetFieldName field is not set in service config %+v", string(c)) |
| 175 | } |
| 176 | name, config, err := parseChildPolicyConfigs(cfgJSON.ChildPolicy, cfgJSON.ChildPolicyConfigTargetFieldName) |
| 177 | if err != nil { |
| 178 | return nil, err |
| 179 | } |
| 180 | lbCfg.childPolicyName = name |
| 181 | lbCfg.childPolicyConfig = config |
| 182 | lbCfg.childPolicyTargetField = cfgJSON.ChildPolicyConfigTargetFieldName |
| 183 | return lbCfg, nil |
| 184 | } |
| 185 | |
| 186 | func parseRLSProto(rlsProto *rlspb.RouteLookupConfig) (*lbConfig, error) { |
| 187 | // Validations specified on the `grpc_keybuilders` field are performed here. |