Skip to content

Commit c879806

Browse files
committed
format
1 parent 326d2ad commit c879806

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,56 @@
11
/*
2-
* Copyright 2021 Red Hat, Inc. and/or its affiliates
3-
* and other contributors as indicated by the @author tags.
2+
* Copyright 2021 Red Hat, Inc. and/or its affiliates and other contributors as indicated by
3+
* the @author tags.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License. You may obtain a copy of the License at
87
*
98
* http://www.apache.org/licenses/LICENSE-2.0
109
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
1614
*/
1715

1816
package io.javaoperatorsdk.operator.processing.dependent.kubernetes;
1917

20-
import com.fasterxml.jackson.databind.ObjectMapper;
21-
import com.fasterxml.jackson.databind.node.ObjectNode;
18+
import java.util.Objects;
19+
2220
import io.fabric8.kubernetes.api.model.HasMetadata;
2321
import io.fabric8.kubernetes.api.model.ObjectMeta;
2422
import io.javaoperatorsdk.operator.processing.event.source.filter.OnUpdateFilter;
2523

26-
import java.util.Objects;
24+
import com.fasterxml.jackson.databind.ObjectMapper;
25+
import com.fasterxml.jackson.databind.node.ObjectNode;
2726

2827
/**
29-
* addresses the additional events noted on https://github.com/fabric8io/kubernetes-client/issues/5215
28+
* addresses the additional events noted on
29+
* https://github.com/fabric8io/kubernetes-client/issues/5215
3030
*/
3131
public class MetadataAwareOnUpdateFilter<T extends HasMetadata> implements OnUpdateFilter<T> {
3232

33-
private static final ObjectMapper mapper = new ObjectMapper();
34-
35-
@Override
36-
public boolean accept(HasMetadata newResource, HasMetadata oldResource) {
37-
ObjectMeta newMetadata = newResource.getMetadata();
38-
ObjectMeta oldMetadata = oldResource.getMetadata();
39-
// quick check if anything meaningful has changed
40-
if (!Objects.equals(newMetadata.getAnnotations(), oldMetadata.getAnnotations())
41-
|| !Objects.equals(newMetadata.getLabels(), oldMetadata.getLabels())
42-
|| !Objects.equals(newMetadata.getGeneration(), oldMetadata.getGeneration())) {
43-
return true;
44-
}
45-
// check everything else besides the metadata
46-
// since the hierarchy of model may not implement hashCode/equals, we'll convert to a generic form
47-
// that should be less expensive than full serialization
48-
var newNode = (ObjectNode)mapper.valueToTree(newResource);
49-
newNode.remove("metadata");
50-
var oldNode = (ObjectNode)mapper.valueToTree(oldResource);
51-
oldNode.remove("metadata");
52-
return !oldNode.equals(newNode);
33+
private static final ObjectMapper mapper = new ObjectMapper();
34+
35+
@Override
36+
public boolean accept(HasMetadata newResource, HasMetadata oldResource) {
37+
ObjectMeta newMetadata = newResource.getMetadata();
38+
ObjectMeta oldMetadata = oldResource.getMetadata();
39+
// quick check if anything meaningful has changed
40+
if (!Objects.equals(newMetadata.getAnnotations(), oldMetadata.getAnnotations())
41+
|| !Objects.equals(newMetadata.getLabels(), oldMetadata.getLabels())
42+
|| !Objects.equals(newMetadata.getGeneration(), oldMetadata.getGeneration())) {
43+
return true;
5344
}
45+
// check everything else besides the metadata
46+
// since the hierarchy of model may not implement hashCode/equals, we'll convert to a generic
47+
// form
48+
// that should be less expensive than full serialization
49+
var newNode = (ObjectNode) mapper.valueToTree(newResource);
50+
newNode.remove("metadata");
51+
var oldNode = (ObjectNode) mapper.valueToTree(oldResource);
52+
oldNode.remove("metadata");
53+
return !oldNode.equals(newNode);
54+
}
5455

5556
}

0 commit comments

Comments
 (0)