Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #7 from integr8ly/INTLY-3888
Browse files Browse the repository at this point in the history
Intly 3888
  • Loading branch information
maleck13 authored Nov 27, 2019
2 parents b3ac082 + 471a1ab commit 8ee86c2
Show file tree
Hide file tree
Showing 522 changed files with 16,520 additions and 8,490 deletions.
8 changes: 3 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ required = [
# revision for tag "kubernetes-1.12.3"
revision = "3dcf91f64f638563e5106f21f50c31fa361c918d"

[[override]]
name = "github.com/openshift/api"
# revision for tag "openshift 3.11"
revision = "8741ff068a473be041d7bafb4502c12e4f10aab5"


[[override]]
name = "github.com/openshift/client-go"
# revision for tag "openshift 3.11"
revision = "431ec9a26e5021f35fa41ee9a89842db9bfdb370"

[[override]]
name = "k8s.io/api"
# revision for tag "kubernetes-1.12.3"
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PROJECT=heimdall-operator
REG=quay.io
TAG=master
COMPILE_TARGET=./tmp/_output/bin/$(PROJECT)
NAMESPACE=""

SHELL=/bin/bash

Expand All @@ -24,6 +25,14 @@ setup/moq:
dep ensure
cd vendor/github.com/matryer/moq/ && go install .

.PHONY: code/run
code/run:
@operator-sdk up local --namespace=$(NAMESPACE)

.PHONY: test/unit
test/unit:
@./scripts/ci/unit_test.sh

.PHONY: image/build
image/build:
@operator-sdk build $(REG)/$(ORG)/$(PROJECT):$(TAG)
Expand Down
25 changes: 15 additions & 10 deletions pkg/cluster/deployments_deployment_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ func (ol *ObjectsLabeler) LabelAllDeploymentsAndDeploymentConfigs(ctx context.Co
if dep.Labels == nil {
dep.Labels = map[string]string{}
}
if matchRegex.MatchString(dep.Name) {
fmt.Println("skipping ", dep.Name, " as matched by excludePattern "+excludePattern)
continue
if excludePattern != "" {
if matchRegex.MatchString(dep.Name) {
fmt.Println("skipping ", dep.Name, " as matched by excludePattern "+excludePattern)
continue
}
}
for k, v := range labels {
dep.Labels[k] = v
Expand Down Expand Up @@ -93,9 +95,11 @@ func (ol *ObjectsLabeler) RemoveLabelsAnnotations(ctx context.Context, labels ma
}

for _, dc := range dcList.Items {
if matchRegex.MatchString(dc.Name) {
fmt.Println("skipping ", dc.Name, " as matched by excludePattern")
continue
if excludePattern != "" {
if matchRegex.MatchString(dc.Name) {
fmt.Println("skipping ", dc.Name, " as matched by excludePattern")
continue
}
}

if dc.Labels != nil {
Expand All @@ -113,10 +117,11 @@ func (ol *ObjectsLabeler) RemoveLabelsAnnotations(ctx context.Context, labels ma
}
}
for _, dep := range depList.Items {

if matchRegex.MatchString(dep.Name) {
fmt.Println("skipping ", dep.Name, " as matched by excludePattern")
continue
if excludePattern != "" {
if matchRegex.MatchString(dep.Name) {
fmt.Println("skipping ", dep.Name, " as matched by excludePattern")
continue
}
}
if dep.Labels != nil {
for k, _ := range labels {
Expand Down
49 changes: 33 additions & 16 deletions pkg/cluster/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (is *ImageService) FindImagesFromImageChangeParams(defaultNS string, params
for _, c := range p.Spec.Containers {
if c.Image == imageSHA {
podContainerRef.Containers = append(podContainerRef.Containers, c.Name)
parsedImage.Pods = append(parsedImage.Pods, podContainerRef)
}
}
parsedImage.Pods = append(parsedImage.Pods, podContainerRef)
}
images = append(images, parsedImage)
continue
Expand Down Expand Up @@ -126,32 +126,49 @@ func (is *ImageService) FindImagesFromLabels(ns string, deploymentLabels map[str
return nil, errors.Wrap(err, "failed to list pods with labels "+strings.Join(selectors, ","))
}
// create a unique set of images
imageIDS := map[string]string{}
imageIDS := map[string]*domain.ClusterImage{}
// get all images from pods
for _, p := range pods.Items {
pcr := domain.PodAndContainerRef{
Name: p.Name,
Namespace: p.Namespace,
Containers: []string{},
}
for _, cs := range p.Status.ContainerStatuses {
//check if this image is coming from the the internal registry if so skip
if strings.Contains(cs.ImageID, "docker-registry") {
log.Info("skipping image ", cs.ImageID, " as it is internal. It will be picked up as part of image stream checking ")
continue
}
imageID := strings.Replace(cs.ImageID, "docker-pullable://", "", 1)
// check have we looked at this image already. Can happen when multiple pods
if _, ok := imageIDS[imageID]; !ok {
imageIDS[imageID] = cs.Image
i := ParseImage(cs.Image)
pcr := domain.PodAndContainerRef{
Name: p.Name,
Namespace: p.Namespace,
Containers: []string{},
}

i.SHA256Path = imageID
for _, c := range p.Spec.Containers {
pcr.Containers = append(pcr.Containers, c.Name)
// check have we looked at this image already. Can happen when multiple pods or multiple containers with same image
var image *domain.ClusterImage
if i, ok := imageIDS[imageID]; ok {
image = i
} else {
image = ParseImage(cs.Image)
image.SHA256Path = imageID

}

for _, c := range p.Spec.Containers {
pcr.Containers = append(pcr.Containers, c.Name)
}

foundPod := false
for _, sp := range image.Pods {
if sp.Name == p.Name {
foundPod = true
break
}
i.Pods = append(i.Pods, pcr)
images = append(images, i)
}
if !foundPod {
image.Pods = append(image.Pods, pcr)
}
if _, ok := imageIDS[imageID]; !ok {
imageIDS[imageID] = image
images = append(images, image)
}
}
}
Expand Down
Loading

0 comments on commit 8ee86c2

Please sign in to comment.