Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pilot/pkg/autoregistration/internal/state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (s *Store) UpdateHealth(proxyID, entryName, entryNs string, condition *v1al
}

// replace the updated status
wle := status.UpdateConfigCondition(*cfg, condition)
wle := status.UpdateIstioConfigCondition(*cfg, condition)
// update the status
_, err := s.store.UpdateStatus(wle)
if err != nil {
Expand All @@ -89,7 +89,7 @@ func (s *Store) UpdateHealth(proxyID, entryName, entryNs string, condition *v1al
// DeleteHealthCondition updates WorkloadEntry of a workload that is not using auto-registration
// to remove information about the health status (since we can no longer be certain about it).
func (s *Store) DeleteHealthCondition(wle config.Config) error {
wle = status.DeleteConfigCondition(wle, status.ConditionHealthy)
wle = status.DeleteIstioConfigCondition(wle, status.ConditionHealthy)
// update the status
_, err := s.store.UpdateStatus(wle)
if err != nil && !errors.IsNotFound(err) {
Expand Down
7 changes: 0 additions & 7 deletions pilot/pkg/config/aggregate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,6 @@ func (cr *store) UpdateStatus(c config.Config) (string, error) {
return cr.writer.UpdateStatus(c)
}

func (cr *store) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
if cr.writer == nil {
return "", errorUnsupported
}
return cr.writer.Patch(orig, patchFn)
}

type storeCache struct {
model.ConfigStore
caches []model.ConfigStoreController
Expand Down
4 changes: 0 additions & 4 deletions pilot/pkg/config/file/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ func (s *KubeSource) UpdateStatus(config config.Config) (newRevision string, err
return s.inner.UpdateStatus(config)
}

func (s *KubeSource) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
return s.inner.Patch(orig, patchFn)
}

func (s *KubeSource) Delete(typ config.GroupVersionKind, name, namespace string, resourceVersion *string) error {
return s.inner.Delete(typ, name, namespace, resourceVersion)
}
Expand Down
40 changes: 0 additions & 40 deletions pilot/pkg/config/kube/crd/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import (
"io"
"reflect"

"github.com/hashicorp/go-multierror"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
kubeyaml "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/yaml"

"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/schema/collections"
Expand All @@ -45,17 +43,6 @@ func FromJSON(s resource.Schema, js string) (config.Spec, error) {
return c, nil
}

func FromJSONStrict(s resource.Schema, js string) (config.Spec, error) {
c, err := s.NewInstance()
if err != nil {
return nil, err
}
if err = config.ApplyJSONStrict(c, js); err != nil {
return nil, err
}
return c, nil
}

func StatusJSONFromMap(schema resource.Schema, jsonMap *json.RawMessage) (config.Status, error) {
if jsonMap == nil {
return nil, nil
Expand All @@ -75,33 +62,6 @@ func StatusJSONFromMap(schema resource.Schema, jsonMap *json.RawMessage) (config
return status, nil
}

// FromYAML converts a canonical YAML to a proto message
func FromYAML(s resource.Schema, yml string) (config.Spec, error) {
c, err := s.NewInstance()
if err != nil {
return nil, err
}
if err = config.ApplyYAML(c, yml); err != nil {
return nil, err
}
return c, nil
}

// FromJSONMap converts from a generic map to a proto message using canonical JSON encoding
// JSON encoding is specified here: https://developers.google.com/protocol-buffers/docs/proto3#json
func FromJSONMap(s resource.Schema, data any) (config.Spec, error) {
// Marshal to YAML bytes
str, err := yaml.Marshal(data)
if err != nil {
return nil, err
}
out, err := FromYAML(s, string(str))
if err != nil {
return nil, multierror.Prefix(err, fmt.Sprintf("YAML decoding error: %v", string(str)))
}
return out, nil
}

type ConversionFunc = func(s resource.Schema, js string) (config.Spec, error)

func ConvertObjectInternal(schema resource.Schema, object IstioObject, domain string, convert ConversionFunc) (*config.Config, error) {
Expand Down
12 changes: 0 additions & 12 deletions pilot/pkg/config/kube/crdclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,18 +272,6 @@ func (cl *Client) UpdateStatus(cfg config.Config) (string, error) {
return meta.GetResourceVersion(), nil
}

// Patch applies only the modifications made in the PatchFunc rather than doing a full replace. Useful to avoid
// read-modify-write conflicts when there are many concurrent-writers to the same resource.
func (cl *Client) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
modified, patchType := patchFn(orig.DeepCopy())

meta, err := patch(cl.client, orig, getObjectMetadata(orig), modified, getObjectMetadata(modified), patchType)
if err != nil {
return "", err
}
return meta.GetResourceVersion(), nil
}

// Delete implements store interface
// `resourceVersion` must be matched before deletion is carried out. If not possible, a 409 Conflict status will be
func (cl *Client) Delete(typ config.GroupVersionKind, name, namespace string, resourceVersion *string) error {
Expand Down
19 changes: 0 additions & 19 deletions pilot/pkg/config/kube/crdclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"go.uber.org/atomic"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/gateway-api/pkg/consts"

"istio.io/api/meta/v1alpha1"
Expand Down Expand Up @@ -239,24 +238,6 @@ func TestClient(t *testing.T) {
return nil
})

// check we can patch items
var patchedCfg config.Config
if _, err := store.(*Client).Patch(*cfg, func(cfg config.Config) (config.Config, types.PatchType) {
cfg.Annotations["fizz"] = "buzz"
patchedCfg = cfg
return cfg, types.JSONPatchType
}); err != nil {
t.Errorf("unexpected err in Patch: %v", err)
}
// validate it is updated
retry.UntilSuccessOrFail(t, func() error {
cfg := store.Get(r.GroupVersionKind(), configName, configMeta.Namespace)
if cfg == nil || !reflect.DeepEqual(cfg.Meta, patchedCfg.Meta) {
return fmt.Errorf("get(%v) => got unexpected object %v", name, cfg)
}
return nil
})

// Check we can remove items
if err := store.Delete(r.GroupVersionKind(), configName, configNamespace, nil); err != nil {
t.Fatalf("failed to delete: %v", err)
Expand Down
4 changes: 0 additions & 4 deletions pilot/pkg/config/kube/file/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,6 @@ func (c *Controller) UpdateStatus(config config.Config) (newRevision string, err
return "", errUnsupportedOp
}

func (c *Controller) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
return "", errUnsupportedOp
}

func (c *Controller) Delete(typ config.GroupVersionKind, name, namespace string, _ *string) error {
return errUnsupportedOp
}
Expand Down
4 changes: 0 additions & 4 deletions pilot/pkg/config/kube/gateway/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,6 @@ func (c *Controller) UpdateStatus(config config.Config) (newRevision string, err
return "", errUnsupportedOp
}

func (c *Controller) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
return "", errUnsupportedOp
}

func (c *Controller) Delete(typ config.GroupVersionKind, name, namespace string, _ *string) error {
return errUnsupportedOp
}
Expand Down
20 changes: 0 additions & 20 deletions pilot/pkg/config/memory/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package memory
import (
"fmt"

"k8s.io/apimachinery/pkg/types"

"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/config"
"istio.io/istio/pkg/config/schema/collection"
Expand Down Expand Up @@ -123,24 +121,6 @@ func (c *Controller) UpdateStatus(config config.Config) (newRevision string, err
return newRevision, err
}

func (c *Controller) Patch(orig config.Config, patchFn config.PatchFunc) (newRevision string, err error) {
cfg, typ := patchFn(orig.DeepCopy())
switch typ {
case types.MergePatchType:
case types.JSONPatchType:
default:
return "", fmt.Errorf("unsupported merge type: %s", typ)
}
if newRevision, err = c.configStore.Patch(cfg, patchFn); err == nil {
c.monitor.ScheduleProcessEvent(ConfigEvent{
old: orig,
config: cfg,
event: model.EventUpdate,
})
}
return newRevision, err
}

func (c *Controller) Delete(kind config.GroupVersionKind, key, namespace string, resourceVersion *string) error {
if config := c.Get(kind, key, namespace); config != nil {
if err := c.configStore.Delete(kind, key, namespace, resourceVersion); err != nil {
Expand Down
33 changes: 0 additions & 33 deletions pilot/pkg/config/memory/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,39 +227,6 @@ func (cr *store) UpdateStatus(cfg config.Config) (string, error) {
return cr.Update(cfg)
}

func (cr *store) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
cr.mutex.Lock()
defer cr.mutex.Unlock()

gvk := orig.GroupVersionKind
s, ok := cr.schemas.FindByGroupVersionKind(gvk)
if !ok {
return "", fmt.Errorf("unknown type %v", gvk)
}

cfg, _ := patchFn(orig)
if !cr.skipValidation {
if _, err := s.ValidateConfig(cfg); err != nil {
return "", err
}
}

_, ok = cr.data[gvk]
if !ok {
return "", errNotFound
}
ns, exists := cr.data[gvk][orig.Namespace]
if !exists {
return "", errNotFound
}

rev := time.Now().String()
cfg.ResourceVersion = rev
ns[cfg.Name] = cfg

return rev, nil
}

// hasConflict checks if the two resources have a conflict, which will block Update calls
func hasConflict(existing, replacement config.Config) bool {
if replacement.ResourceVersion == "" {
Expand Down
4 changes: 0 additions & 4 deletions pilot/pkg/model/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,3 @@ func (fs *authzFakeStore) Update(config.Config) (string, error) {
func (fs *authzFakeStore) UpdateStatus(config.Config) (string, error) {
return "not implemented", nil
}

func (fs *authzFakeStore) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
return "not implemented", nil
}
4 changes: 0 additions & 4 deletions pilot/pkg/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ type ConfigStore interface {
Update(config config.Config) (newRevision string, err error)
UpdateStatus(config config.Config) (newRevision string, err error)

// Patch applies only the modifications made in the PatchFunc rather than doing a full replace. Useful to avoid
// read-modify-write conflicts when there are many concurrent-writers to the same resource.
Patch(orig config.Config, patchFn config.PatchFunc) (string, error)

// Delete removes an object from the store by key
// For k8s, resourceVersion must be fulfilled before a deletion is carried out.
// If not possible, a 409 Conflict status will be returned.
Expand Down
32 changes: 0 additions & 32 deletions pilot/pkg/model/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ trafficPolicy:
},
}

badSchema := schemaFor("bad", "bad-name")
if _, err := crd.FromYAML(badSchema, wantYAML); err == nil {
t.Errorf("FromYAML should have failed using Schema with bad MessageName")
}

gotJSON, err := protomarshal.ToJSON(msg)
if err != nil {
t.Errorf("ToJSON failed: %v", err)
Expand Down Expand Up @@ -158,18 +153,6 @@ trafficPolicy:
t.Error("should produce an error")
}

gotFromYAML, err := crd.FromYAML(destinationRuleSchema, wantYAML)
if err != nil {
t.Errorf("FromYAML failed: %v", err)
}
if !reflect.DeepEqual(gotFromYAML, msg) {
t.Errorf("FromYAML failed: got %+v want %+v", spew.Sdump(gotFromYAML), spew.Sdump(msg))
}

if _, err = crd.FromYAML(destinationRuleSchema, ":"); err == nil {
t.Errorf("should produce an error")
}

gotJSONMap, err := protomarshal.ToJSONMap(msg)
if err != nil {
t.Errorf("ToJSONMap failed: %v", err)
Expand All @@ -181,19 +164,4 @@ trafficPolicy:
if _, err = protomarshal.ToJSONMap(nil); err == nil {
t.Error("should produce an error")
}

gotFromJSONMap, err := crd.FromJSONMap(destinationRuleSchema, wantJSONMap)
if err != nil {
t.Errorf("FromJSONMap failed: %v", err)
}
if !reflect.DeepEqual(gotFromJSONMap, msg) {
t.Errorf("FromJSONMap failed: got %+v want %+v", spew.Sdump(gotFromJSONMap), spew.Sdump(msg))
}

if _, err = crd.FromJSONMap(destinationRuleSchema, 1); err == nil {
t.Error("should produce an error")
}
if _, err = crd.FromJSONMap(destinationRuleSchema, ":"); err == nil {
t.Errorf("should produce an error")
}
}
4 changes: 0 additions & 4 deletions pilot/pkg/model/fake_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func (s *FakeStore) Update(cfg config.Config) (newRevision string, err error) {

func (*FakeStore) UpdateStatus(config config.Config) (string, error) { return "", nil }

func (*FakeStore) Patch(orig config.Config, patchFn config.PatchFunc) (string, error) {
return "", nil
}

func (s *FakeStore) Delete(typ config.GroupVersionKind, name, namespace string, rv *string) error {
nsConfigs := s.store[typ]
if nsConfigs == nil {
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/model/status/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func GetCondition(conditions []*v1alpha1.IstioCondition, condition string) *v1al
return nil
}

func UpdateConfigCondition(cfg config.Config, condition *v1alpha1.IstioCondition) config.Config {
func UpdateIstioConfigCondition(cfg config.Config, condition *v1alpha1.IstioCondition) config.Config {
cfg = cfg.DeepCopy()
var status *v1alpha1.IstioStatus
if cfg.Status == nil {
Expand All @@ -86,7 +86,7 @@ func updateCondition(conditions []*v1alpha1.IstioCondition, condition *v1alpha1.
return append(conditions, condition)
}

func DeleteConfigCondition(cfg config.Config, condition string) config.Config {
func DeleteIstioConfigCondition(cfg config.Config, condition string) config.Config {
c, ok := cfg.Status.(*v1alpha1.IstioStatus)
if !ok {
return cfg
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/serviceregistry/serviceregistry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1530,12 +1530,12 @@ func setHealth(cfg config.Config, healthy bool) config.Config {
}
cfg.Annotations[status.WorkloadEntryHealthCheckAnnotation] = "true"
if healthy {
return status.UpdateConfigCondition(cfg, &v1alpha1.IstioCondition{
return status.UpdateIstioConfigCondition(cfg, &v1alpha1.IstioCondition{
Type: status.ConditionHealthy,
Status: status.StatusTrue,
})
}
return status.UpdateConfigCondition(cfg, &v1alpha1.IstioCondition{
return status.UpdateIstioConfigCondition(cfg, &v1alpha1.IstioCondition{
Type: status.ConditionHealthy,
Status: status.StatusFalse,
})
Expand Down
Loading