github.com/GoogleContainerTools/skaffold@v1.39.18/pkg/skaffold/runner/changeset.go (about) 1 /* 2 Copyright 2021 The Skaffold Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package runner 18 19 import ( 20 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" 21 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/sync" 22 ) 23 24 type ChangeSet struct { 25 needsRebuild []*latest.Artifact 26 rebuildTracker map[string]*latest.Artifact 27 needsResync []*sync.Item 28 resyncTracker map[string]*sync.Item 29 needsRetest map[string]bool // keyed on artifact image name 30 needsRedeploy bool 31 needsReload bool 32 } 33 34 // NeedsRebuild gets the value of needsRebuild, which itself is not expected to be changed outside ChangeSet 35 func (c *ChangeSet) NeedsRebuild() []*latest.Artifact { 36 return c.needsRebuild 37 } 38 39 // NeedsResync gets the value of needsResync, which itself is not expected to be changed outside ChangeSet 40 func (c *ChangeSet) NeedsResync() []*sync.Item { 41 return c.needsResync 42 } 43 44 // NeedsRedeploy gets the value of needsRedeploy, which itself is not expected to be changed outside ChangeSet 45 func (c *ChangeSet) NeedsRedeploy() bool { 46 return c.needsRedeploy 47 } 48 49 // NeedsRetest gets the value of needsRetest, which itself is not expected to be changed outside ChangeSet 50 func (c *ChangeSet) NeedsRetest() map[string]bool { 51 return c.needsRetest 52 } 53 54 // NeedsReload gets the value of needsReload, which itself is not expected to be changed outside ChangeSet 55 func (c *ChangeSet) NeedsReload() bool { 56 return c.needsReload 57 } 58 59 func (c *ChangeSet) AddRebuild(a *latest.Artifact) { 60 if _, ok := c.rebuildTracker[a.ImageName]; ok { 61 return 62 } 63 if c.rebuildTracker == nil { 64 c.rebuildTracker = map[string]*latest.Artifact{} 65 } 66 c.rebuildTracker[a.ImageName] = a 67 c.needsRebuild = append(c.needsRebuild, a) 68 } 69 70 func (c *ChangeSet) AddRetest(a *latest.Artifact) { 71 if c.needsRetest == nil { 72 c.needsRetest = make(map[string]bool) 73 } 74 c.needsRetest[a.ImageName] = true 75 } 76 77 func (c *ChangeSet) AddResync(s *sync.Item) { 78 if _, ok := c.resyncTracker[s.Image]; ok { 79 return 80 } 81 if c.resyncTracker == nil { 82 c.resyncTracker = map[string]*sync.Item{} 83 } 84 c.resyncTracker[s.Image] = s 85 c.needsResync = append(c.needsResync, s) 86 } 87 88 func (c *ChangeSet) ResetBuild() { 89 c.rebuildTracker = make(map[string]*latest.Artifact) 90 c.needsRebuild = nil 91 } 92 93 func (c *ChangeSet) ResetSync() { 94 c.resyncTracker = make(map[string]*sync.Item) 95 c.needsResync = nil 96 } 97 98 func (c *ChangeSet) ResetDeploy() { 99 c.needsRedeploy = false 100 } 101 102 // Redeploy marks that deploy is expected to happen. 103 func (c *ChangeSet) Redeploy() { 104 c.needsRedeploy = true 105 } 106 107 // Reload marks that reload is expected to happen. 108 func (c *ChangeSet) Reload() { 109 c.needsReload = true 110 } 111 112 func (c *ChangeSet) ResetTest() { 113 c.needsRetest = make(map[string]bool) 114 }